emulating boost::mpl::set (was Re: can't use variadic template arg in dependent type

Larry Evans cppljevans at cos-internet.com
Tue Jan 9 09:41:25 PST 2007


On 01/09/2007 11:12 AM, Larry Evans wrote:
[snip]
> This c++ "trick" was described on section 9.10 of the book
> described here:
> 
> http://www.boost-consulting.com/metaprogramming-book.html
> 
> and the cloest c++ counterpart to what I'm trying to do
> was posted in another message to this newsgroup:
> 
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=46428 
> 
[snip]
Maybe I should explain this "trick".  IIUC, for c++ function template:

template<T0,T1,...,Tn> void f(T0 t0, T1 t1,...Tn tn);

if the args are partially explicitly specified at the call,
e.g.:

   f<A0,A1>(a0,a1,...an)l

then the remaining template arguments, i.e. T2...Tn, are
"wildcards", i.e. they can be anything that's consistent
with the actual arguments, a2...an.  In the case of the code in
art_group=digitalmars.D&article_id=46428, the explicit argument
was the type whose membership in the set was being queried.
i.e.

   has_key_tester<int>(p_int_float)

explicitly specifies the desired member, i.e. int, and
the c++ function template overload resolution attempts to
find a Tail... such that

   typeof(p_int_float) = set<int,Tail...>

and, of course it does; hence, the result is mpl::boost_<true>.
On the other hand, if no such Tail... is possible, then
the more general has_key_tester is chosen and the result
type is mpl::boost_<false>.

I've looked at http://www.digitalmars.com/d/templates-revisited.html
, and that seems closes to what I'm aiming at (since it does
mention SFINAE); however, I still can't see how to do it.
Does anyone else?



More information about the Digitalmars-d mailing list