|
Boost Users : |
Subject: Re: [Boost-users] Using boost_foreach with c++ enumerations
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-08-06 11:02:38
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_all.zip
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net