list all values in a C++ enum

Viewed 75

We have C++ enum, like

    enum class ABC : int {
        A = 2,
        B = 3,
        C = 5,
        D = 7,
        E = 11,
        F = 13,
    };

And we want to at compile time, generate the following code automatically (not manual typing):

    func("ABC.A", ABC::A);
    func("ABC.B", ABC::B);
    func("ABC.C", ABC::C);
    func("ABC.D", ABC::D);
    func("ABC.E", ABC::E);
    func("ABC.F", ABC::F);

In other word, we want to list all items in an enum automatically.

How can we do that?

0 Answers
Related