Hierarchical enumeration?
Does boost (or any other lib in C++) have facility to support smth that resembles hierarchical enumeration? I would like to have something like the following: enum Hierarchy { Store::Clothing = 1 Store::Electronics, Building::Residential, Building::Commercial } ... Hierarchy h = Hierarchy::Building::Commercial; ... if (h == Hierarchy::Store) { if (h == Hierarchy::Store::Clothing) std::cout<<"clothing"; } ...
Archie14 a écrit :
Does boost (or any other lib in C++) have facility to support smth that resembles hierarchical enumeration? I would like to have something like the following:
enum Hierarchy { Store::Clothing = 1 Store::Electronics, Building::Residential, Building::Commercial }
... Hierarchy h = Hierarchy::Building::Commercial; ... if (h == Hierarchy::Store) { if (h == Hierarchy::Store::Clothing)
How could h be equal to different things at the same time? What you're looking for seems to be dynamic_cast.
Since your types are known at compile time, I think this belongs to the class of problems that systems programmers would traditionally solve with bit masks.
What you're looking for seems to be dynamic_cast.
But I think you're seeking a solution with more explicit support from the language. Yes if you lay it out as a class hierarchy then I agree with Mathias that dynamic_cast should work well. Kevin
participants (3)
-
Archie14
-
Kevin Kassil
-
Mathias Gaunard