Boost logo

Boost Users :

From: Joel Falcou (joel.falcou_at_[hidden])
Date: 2008-05-28 06:42:02


Hansi a écrit :
> Joel Falcou schrieb:
>> Just either use MPL HAS_XXX macro or Eric Niebler fast type checking to
>> test if the tempalte Type has the typename you need defined.
>
> What is the Eric Niebler fast type checking? in which library is this?

Check the documentation of Proto, which should be available in the Vault.

Basically, here's the gist of how I reused it as a "tag" feature on
class I wanted to sort by the fact they have or not some features.

Let's say you want to know if type X has some features. You use a small
structure called has_feat :

struct has_foo { typedef void foo_type; };

Let's say you have two class Bar1 & Bar2. Bar1 has features foo while
Bar2 has none. To tag this, make Bar1 inherit from has_foo :

class Bar1 : public has_foo { ... };

Now, to check if a given type T has foo features (hence inherits from
has_foo), you have to build a simple metafunction :

template<class C, class V = void>
struct check_for_foo : false_ {};

template<class C>
struct check_for_foo<C,typename C::foo_type> : true_ {};

Then, using

check_for_foo<T>::type will give you a MPL boolean that tells you if T
"has foo" features.


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