Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Detecting if a tag is a proto type or not
From: Eric Niebler (eric_at_[hidden])
Date: 2008-11-17 11:35:31


Joel Falcou wrote:
> Eric Niebler a écrit :
>> Well, they're defined in the boost::proto::tag namespace. You can play
>> tricks with ADL and sizeof....
>
> Care to elaborate a few ?

Something like this:

namespace boost { namespace proto { namespace tag {
   template<typename T>
   char check_is_proto_tag(T);
}}}

namespace not_proto
{
   char (&check_is_proto_tag(...))[2];
}

using not_proto::check_is_proto_tag;

template<typename T>
struct is_proto_tag
   : boost::mpl::bool_<sizeof(check_is_proto_tag(T()))==1>
{};

struct not_proto_tag {};

BOOST_MPL_ASSERT((is_proto_tag<boost::proto::tag::plus>));
BOOST_MPL_ASSERT_NOT((is_proto_tag<not_proto_tag>));

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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