2

Possible Duplicate:
C++: Iterate through an enum
Enumerate over an enum in C++

I have:

  enum topics {gui, combat}
  std::map <topics, std::vector<cSubscriber *>> subscribers;   

And I want something like (pseudocode):

   FOR EACH (value in topics enum)
   {
       std::vector<cSubscriber *> & temp = subscribers[value];
   }

How can I do that in C++11? I know that there is new foreach for containers but I don't think it works with enums.

Community
  • 1
  • 1
user1873947
  • 1,781
  • 3
  • 27
  • 47
  • You don't. Unless you make a list of all the enum values manually. –  Jan 29 '13 at 13:11
  • 2
    Usually you define a last dummy member of the enum an use that as the count of possible values. But of course this assumes there's no "jumps" in the values (and that the first one is 0, although this is not a big deal). – Andy Prowl Jan 29 '13 at 13:11
  • @Andy Prowl I see, it seems to be good and easy. I will just put a coment not to modify values. – user1873947 Jan 29 '13 at 13:12
  • 2
    You may find [this](http://stackoverflow.com/a/2941915/1043806) answer useful... or [that](http://stackoverflow.com/a/1391479/1043806) one. – nameless Jan 29 '13 at 13:14

0 Answers0