#include <iostream>
#include <enum>
#include <algorithm>
enum Color { Red = 1, Green = 2, Blue = 23 };
int main()
{
auto e = std::enum<Color>();
for( auto v: e)
{
std::cout << "Elem: " << v << "\n";
}
std::cout << "Size: " << e.size() << "\n";
std::cout << "Largest: " << std::max_element(e.begin(), e.end()) << "\n";
return 0;
}
Elem: 1
Elem: 2
Elem: 23
Size: 3
Largest: 23
const auto & e =Color.array
On Tuesday, 20 June 2017 20:34:28 PDT Halfdan Ingvarsson wrote:
> I'd like to propose a simple, but very useful utility class for the
> standard library: std::enum.
You need to find a different name. We can't have a class whose name is a
reserved keyword.
You're asking for enum reflection. There are many proposals about that, both
restricted to enums as well as generic (reflection for everything). The
restricted proposals haven't gained much traction, so everything now depends
on the full reflection proposals being accepted.
I won't think it can be done with only add lib.For the samething I would suggest enum class will have a static const variable array.so that you could write
const auto & e =Color.array
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2384155.IuquL1aeVr%40tjmaciei-mobl1.
I'd like to propose a simple, but very useful utility class for the standard library: std::enum.All it does is take a template parameter, which would be an enum type.It would then allow you to access the individual elements of that enum, in order of declaration, using a nearly identical interface as std::array<> (i.e either through enumerators, or operator[]).
enum E { ZERO = 0, ONE = 1, TWO = 2 };std::map<std::string, int> a = MAKE_MAP(E); // MALE_MAP(E) is equivalent to {{"ZERO", 0}, {"ONE", 1}, {"TWO", 2}}