Avoid type renaming hardcoding

In c++11 code, it would be nice to avoid mentioning a specific enumeration qualifier every time I use an enumeration value - since this is new code and it will be reorganized a lot.

For this purpose, something in the spirit of the last line of this pseudocode is possible:

 enum abc { a,b,c }; // some long code of events which returns the enum value auto e = []()->abc{return abc::b;}(); if (e == std::declval(e)::a) { ... 

If this is not possible in c++11 , will it become possible in C++14 or 17?

+5
source share
1 answer

You are close, you can use decltype :

 if (e == decltype(e)::a) { ... 
+8
source

Source: https://habr.com/ru/post/1259611/


All Articles