Using boost_foreach with c++ enumerations
Hi, Is it possible to use boost_foreach to iterate over the members of a c++ enum? If so, can anybody point me to an example? Many thanks in advance. Best wishes. Tim Burgess Raised Bar Ltd. T: 01827 719822 M: 07989 486976 W: http://www.raisedbar.net
On 8/5/2013 10:49 AM, Tim Burgess wrote:
Hi,
Is it possible to use boost_foreach to iterate over the members of a c++ enum? If so, can anybody point me to an example?
No. BOOST_FOREACH is for ranges, and an enum is not a range. There is no way to do what you're asking because C++ doesn't have the reflection capabilities needed to iterate through all members of an enum. -- Eric Niebler Boost.org http://www.boost.org
On 08/05/13 18:37, Eric Niebler wrote:
On 8/5/2013 10:49 AM, Tim Burgess wrote:
Hi,
Is it possible to use boost_foreach to iterate over the members of a c++ enum? If so, can anybody point me to an example?
No. BOOST_FOREACH is for ranges, and an enum is not a range. There is no way to do what you're asking because C++ doesn't have the reflection capabilities needed to iterate through all members of an enum.
Back in 2005, I hacked together something that might help. See: http://article.gmane.org/gmane.comp.lib.boost.devel/117229 and maybe: https://github.com/boost-vault/Template-Metaprogramming/blob/master/range_al... The range_all.hp which I've got on my local disk has comment: //range_c for enumerations which can include all of the enumeration I think maybe that's what's included in the range_all.zip mentioned above. HTH. -regards, Larry
participants (3)
-
Eric Niebler
-
Larry Evans
-
Tim Burgess