10 Aug
2008
10 Aug
'08
8:23 p.m.
Hello,
how can I build a concept which requires a given type X to either have an associated type named foo or an associated type named bar (silly names for example purpose). Checking for both is easy but i can't find how to check for OR another.
Maybe using SFINAE? template <class T> struct foo_or_bar { template <class U> static typename U::bar f(); template <class U> static typename U::foo f(); typedef BOOST_TYPEOF(f<T>()) type; }; foo_or_bar<something>::type will give you the type of the "foo" or "bar" nested in "something"... But it's an exclusive OR: if both are present, you have an ambiguity. Anyway I'm pretty sure someone else will find a better way... :-) Bruno