Wednesday, December 28, 2022

Digest for comp.lang.c++@googlegroups.com - 6 updates in 2 topics

David Brown <david.brown@hesbynett.no>: Dec 28 05:09PM +0100

On 27/12/2022 23:31, Alf P. Steinbach wrote:
 
> Say no to the newfangled enum classes, they're Just Wrong. Define the
> enum like this:
 
>     struct Month{ enum Enum{ january = 1, february, ... }; };
 
Why?
 
I can see how it can work, but I have not heard of why it might be
better than enum classes. Can you expand on your reasoning?
JiiPee <kerrttuPoistaTama11@gmail.com>: Dec 28 09:01PM +0200

On 28/12/2022 18:09, David Brown wrote:
 
> Why?
 
> I can see how it can work, but I have not heard of why it might be
> better than enum classes. Can you expand on your reasoning?
 
is it that enum Enum converts directly to an integer, as enum class does
not? Easier to use?
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Dec 28 10:47PM +0100

On 28 Dec 2022 20:01, JiiPee wrote:
> > better than enum classes.  Can you expand on your reasoning?
 
> is it that enum Enum converts directly to an integer, as enum class does
> not? Easier to use?
 
Mainly that.
 
Choosing a class instead of a namespace as container of the enumerator
names is mostly gut-feeling. With class the names can be inherited into
another class, and they can be referred to in a succinct manner via a
local short type alias. With namespace the names can be made available
for unqualified use in a local scope via `using namespace`, or referred
to in a succinct manner via a namespace alias, but not in a class scope.
 
Classes also become almost /necessary/ to express enum generalizations.
For example, 0 is an Input_stream_id; 1 and 2 are Output_stream_id; and
any Input_stream_id or Output_stream_id is a general Stream_id.
Unfortunately class inheritance goes the wrong way for expressing enum
relationships directly, so in the experimental code below (what a more
concise syntax would have to be translated to) there are just implicit
conversions from Input_stream_id and Output_stream_id to Stream_id:
 
 
// struct Input_stream_id{ enum Enum{ in = 0 }; };
// struct Output_stream_id{ enum Enum{ out = 1, err = 2 }; };
 
class Input_stream_id;
struct Input_stream_id_names
{
static const Input_stream_id in; // 0
};
 
class Output_stream_id;
struct Output_stream_id_names
{
static const Output_stream_id out; // 1
static const Output_stream_id err; // 2
};
 
class Input_stream_id:
public Input_stream_id_names
{
const int m_value;
 
public:
explicit constexpr Input_stream_id( const int value ): m_value(
value ) {}
constexpr operator int() const { return m_value; }
};
 
class Output_stream_id:
public Output_stream_id_names
{
const int m_value;
 
public:
explicit constexpr Output_stream_id( const int value ):
m_value( value ) {}
constexpr operator int() const { return m_value; }
};
 
class Stream_id:
public Input_stream_id_names,
public Output_stream_id_names
{
const int m_value;
 
public:
explicit constexpr Stream_id( const int value ): m_value( value
) {}
 
constexpr Stream_id( const Input_stream_id value ): m_value(
value ) {}
constexpr Stream_id( const Output_stream_id value ): m_value(
value ) {}
constexpr operator int() const { return m_value; }
};
 
inline constexpr Input_stream_id Input_stream_id_names::in
= Input_stream_id( 0 );
inline constexpr Output_stream_id Output_stream_id_names::out
= Output_stream_id( 1 );
inline constexpr Output_stream_id Output_stream_id_names::err
= Output_stream_id( 2 );
 
 
- Alf
Tim Rentsch <tr.17687@z991.linuxsc.com>: Dec 28 12:25PM -0800


>> There is a tacit assumption in that statement that longer is
>> always easier to read or more readily comprehended.
 
> No, there isn't.
 
Of course there is. The phrase "brevity-over-clarity" suggests
a false dichotomy between brief and clear. Anyone who pretends
otherwise is just being obtuse.
Tim Rentsch <tr.17687@z991.linuxsc.com>: Dec 28 12:48PM -0800


> Juha Nieminen <nospam@thanks.invalid> writes:
 
>> Maybe you also have a thin skin in addition to a thick skull...
 
> Also an insult.
 
Saying someone has thin skin can be an insult, but it
doesn't have to be. Some people are more sensitive
than others. I have heard someone say something about
how thin or thick someone's skin was, and the statement
was made in a way that I would characterize as a most
benevolent manner.
 
Please note that I am not making any claims as to what
Juha intended in his statement.
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Dec 28 01:38PM -0800

> benevolent manner.
 
> Please note that I am not making any claims as to what
> Juha intended in his statement.
 
I was making a claim as to what Juha intended. By raising an irrelevant
point about a figure of speech, you risk rekindling an argument that had
died out more than a week ago. Please don't do that.
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: