|
Boost Users : |
From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2008-08-10 16:23:32
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
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