1

Topic: Analog scoped enum to a C ++ 11

As though more gracefully to fasten to enum restriction of area of visibility in versions to a C ++ 11? I yet did not invent anything the best, than to turn enum in with the same name namespace but then addressed to type it is necessary to refer a construction of type EnumType:: EnumType that looks somehow clumsily.

2

Re: Analog scoped enum to a C ++ 11

Looking than this area except  still is restricted it is possible structure or class to turn and will be visible such  accordingly only within a class or the structure of other ways is not present

3

Re: Analog scoped enum to a C ++ 11

Hello, reversecode, you wrote: R> except  still it is possible structure or class to turn R> and it will be visible such  accordingly only within a class or structure It is clear. Here the main problem in defining constants with simple, not unique names like Day, Out or Upper. In scoped enum access to them is possible only through the qualifier of a name of type, and all looks very gracefully. It would be desirable to make something similar in a C ++ 03, but it is not too clumsy.

4

Re: Analog scoped enum to a C ++ 11

For that them also would refine in With ++ 11 that  these restrictions well let will be e_day, e_month e_upper or eDay, eMoth eUpper and never was problems or enum SomeStatusValue {ssValue1, ssValue2, ssValue3};  everyones code style

5

Re: Analog scoped enum to a C ++ 11

Hello, reversecode, you wrote: R> well let will be R> e_day, e_month e_upper it is clear that prefixes it is possible to pile any. It would be desirable access possibility to members is exceptional through type qualifiers.

6

Re: Analog scoped enum to a C ++ 11

Well then with crutches  through  https://www.boost.org/doc/libs/1_60_0/l … _enum.html

7

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> As though more gracefully to fasten to enum restriction of area of visibility in versions to a C ++ 11? I eat> yet did not invent anything the best, than to turn enum in with the same name namespace but then addressed to type it is necessary to refer a construction of type EnumType:: EnumType that looks somehow clumsily. And what exactly is clumsy? struct Bit {enum {B0=1, B1=2, B2=4, B3=8};};//int x = Bit:: B0 | Bit:: B2;

8

Re: Analog scoped enum to a C ++ 11

He wants probably Bit x = Bit:: B0 | Bit:: B2;

9

Re: Analog scoped enum to a C ++ 11

Hello, reversecode, you wrote: R> he wants probably R> Bit x = Bit:: B0 | Bit:: B2; so there are no problems struct A: Bit {static int a () {return B0|B2;} enum {B02=B0|B2};}; int x=A:: a (); int y=A:: B02;

10

Re: Analog scoped enum to a C ++ 11

Hello, reversecode, you wrote: R> he wants probably R> Bit x = Bit:: B0 | Bit:: B2;.

11

Re: Analog scoped enum to a C ++ 11

Hello, kov_serg, you wrote: _> _> struct A: Bit {_> static int a () {return B0|B2;} _> enum {B02=B0|B2}; _>}; _> int x=A:: a (); _> int y=A:: B02; _> It is much more clumsy, than double qualification through names namespace and enum.

12

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: R>> he wants probably R>> Bit x = Bit:: B0 | Bit:: B2; I eat>. What for?

13

Re: Analog scoped enum to a C ++ 11

Hello, kov_serg, you wrote: R>>> Bit x = Bit:: B0 | Bit:: B2; I eat>>. _> What for? Then, that the compiler traced variable type, and broke off erratic attempts to appropriate to it the arbitrary numerical value. I with pleasure would forbid also conversion enum in int by default, leaving only explicit, but compilers of the such are not able.

14

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> Then that the compiler traced variable type, and broke off erratic attempts to appropriate to it the arbitrary numerical value. I with pleasure would forbid also conversion enum in int by default, leaving only explicit, but compilers of the such are not able. I use about such approach: struct Color {enum t {Red, Green, Blue};}; At type instructions it is necessary to use Color:: t, constants are specified as Color:: Red, Color:: Green and Color:: Blue. At attempt to appropriate Color:: t "something" the compiler normally swears.

15

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> Hello, kov_serg, you wrote: R>>>> Bit x = Bit:: B0 | Bit:: B2; I eat>>>. _>> What for? I eat> Then that the compiler traced variable type, and broke off erratic attempts to appropriate to it the arbitrary numerical value. I with pleasure would forbid also conversion enum in int by default, leaving only explicit, but compilers of the such are not able. This finishing to the point of irrationality not seems to you that?  you also such types want PositiveDouble, RangeDouble, MultiRangeDouble, DoubleWithAcceptedValues and still such DoubleMeter, FloatTime, LongDoubleMass... And then strike with their conversions? Can not produce is better essence,  superfluous entropy, and use on a maximum the available?

16

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> As though more gracefully to fasten to enum restriction of area of visibility in versions to a C ++ 11? https://rsdn.org/forum/cpp/2646987 the Author: remark Date: 06.09.07 http://rsdn.org/forum/cpp/5877840 the Author: Vain Date: 03.12.14 does not approach?

17

Re: Analog scoped enum to a C ++ 11

Hello, okman, you wrote: O> O> struct Color O> enum t O> About, thanks. I such too use with namespace when the type name can be divided naturally into titles of two independent entities, and here it is impossible when to divide - did not invent anything better, than to give identical names both to that, and another. Like the obvious and elementary idea, and here did not come to mind.

18

Re: Analog scoped enum to a C ++ 11

Hello, kov_serg, you wrote: _> this finishing to the point of irrationality not seems to you that? By no means. If in language there is an idea of strict typification - it needs to be used everywhere, except unusual cases. _> you also such types want Mozhe PositiveDouble, RangeDouble, MultiRangeDouble, DoubleWithAcceptedValues _> and still such DoubleMeter, FloatTime, LongDoubleMass... I do not want. For that simple reason that the type double is intended for calculations, and the range of its values on determination has no ruptures, except pair uncertainties. And the type enum, on the contrary, on determination is not intended for calculations, and its values are not obliged to be adjacent. As a matter of fact, it is such primitive analog of set with constant capacity 1 of which it is possible to make forcedly sets capacity till 32-64. _> Can not produce is better essence,  superfluous entropy, and use on a maximum the available? Available entities are better for using, when they add , safety and efficiency. I would like to have in language some more possibilities for restriction of freedom of the compiler on implicit type conversion, and also steam of tens additional warnings.

19

Re: Analog scoped enum to a C ++ 11

Hello, flt, you wrote: F> https://rsdn.org/forum/cpp/2646987 the Author: remark Date: 06.09.07 F> http://rsdn.org/forum/cpp/5877840 the Author: Vain Date: 03.12.14 Refined decisions. But in critical constructions on time it is necessary to use with care - on elementary in appearance constructions the compiler in a non-release mode  a lot of code, moreover with calls, in the speed can sharply fall.

20

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> I do not want. For that simple reason that the type double is intended for calculations, and the range of its values on determination has no ruptures, except pair uncertainties. And the type enum, on the contrary, on determination is not intended for calculations, and its values are not obliged to be adjacent. As a matter of fact, it is such primitive analog of set with constant capacity 1 of which it is possible to make forcedly sets capacity till 32-64. Here for example function sqrt waits the positive values, asin value from a range [-1. 1]. So it is quite possible to use types with restrictions. Moreover sometimes it would be desirable check on overfillings for example at integer numbers. I eat> Available entities better to use, when they add , safety and efficiency. I would like to have in language some more possibilities for restriction of freedom of the compiler on implicit type conversion, and also steam of tens additional warnings. Nevertheless you probably want to restrict not the compiler, and programmers which will work with this code. You should use not a C ++, he explicitly pursues other aims.

21

Re: Analog scoped enum to a C ++ 11

Hello, kov_serg, you wrote: _> Here for example function sqrt waits the positive values, asin value from a range [-1. 1]. Here types with restrictions, and built-in checks in these functions - at least in debug configurations are necessary not. _> so it is quite possible to use types with restrictions. _> moreover sometimes it would be desirable check on overfillings for example at integer numbers. Such it is necessary to implement not adding of new types, and attaching on existing special qualifiers are could be and invariant expressions, on type assert, automatically calculated at performance. _> Nevertheless you probably want to restrict not the compiler, and programmers which will work with this code. Certainly, and first of all. I want, that in any disputable situation the compiler could notify and me, and any another. But is floppy controlled monitoring system of syntax/semantics I at one compiler yet did not see. _> you should use not a C ++, he explicitly pursues other aims. Also what to me to use in kernel Windows, except a C ++, a C and the assembler?

22

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> As though more gracefully to fasten to enum restriction of area of visibility in versions to a C ++ 11? I eat> yet did not invent anything the best, than to turn enum in with the same name namespace but then addressed to type it is necessary to refer a construction of type EnumType:: EnumType that looks somehow clumsily. Besides  in struct it is possible to do how in java class MyEnum {public: static const MyEnum Value1; static const MyEnum Value2;... public://besides the main operation on concealment of values from global area of visibility, it is possible to do a heap (a demon) the useful methods std:: string toString () const; int toInt () const; static MyEnum fromString (const std::string& str);...};//a minus certainly that it is necessary static to carry out values in cpp a part const MyEnum MyEnum:: Value1; const MyEnum MyEnum:: Value2;

23

Re: Analog scoped enum to a C ++ 11

Hello, sergii.p, you wrote: SP> besides  in struct it is possible to do how in java It will be  in a class, in what a difference? A problem that enum ++ has initially been transferred to a C crookedly - it was necessary to make at once to resolve a construction like "enum public/private", instead of to pull twenty with superfluous years, then to give birth to a perversion in a type "enum struct/class".

24

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> It there will be  in a class, in what a difference? Well as? A difference that each element of listing is an object, instead of scalar type. It is possible to write type such void printEnum (const MyEnum& en) {std:: cout <<en.toString ();} In a case with  enum in struct. At us each type of listing - scalar type, also it is necessary to write something similar on void printEnum (const MyEnum& en) {std:: cout <<MyEnum:: convertToString (en);} it is finite, the matter of taste, but me the first variant intuitively is more clear. Though it and less "in the spirit of a C ++". update: by the way, in such situation it is very easy to forbid implicit conversion in int and it is reverse. It is possible to redefine operator | operator& for masks. In general, it is pure  the approach: all to forbid, and then long to suffer, that though something to resolve

25

Re: Analog scoped enum to a C ++ 11

Hello, Evgenie Muzychenko, you wrote: I eat> Certainly, and first of all. I want, that in any disputable situation the compiler could notify and me, and any another. But is floppy controlled monitoring system of syntax/semantics I at one compiler yet did not see. Really only at you one such problems arose? I eat> And what to me to use in kernel Windows, except a C ++, a C and the assembler? Probably that that compiles in a C/C ++/assembler https://haxe.org/manual/types-enum-instance.html Other question. What for it were necessary for you enum, moreover and isolated. Without them in any way?