|
Boost Users : |
Subject: Re: [Boost-users] Puzzled: compiler can't find a match for function call
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-09-11 14:43:54
AMDG
Zeljko Vrba wrote:
>> Suppose that id_t<K1>::type == id_t<K2>::type == int (for instance). If
>> we pass int, how can the compiler figure out whether it's K1 or K2 that
>> has to be deduced?
>>
> True, but it could look into the ::type typedef, see that it depends on the
> id_t template argument, and proceed in the same way as when you give it
> explicitly written out type. (In fact, that's what I expected would happen,
> since typedef just declares a type alias, not a new type.)
>
A template cannot be instantiated until the argument type is
known. Because templates are Turing complete, it is not possible in general
for the compiler to x-ray class templates.
> OK, I was unsuccessfully trying to make a "template-typedef". Is there
> a way in which I can shorten BF::map<BF::pair<K, int> > to just something
> like id_t<K>, but that works with type-deduction?
>
A solution which works if you don't need partial ordering, is to use SFINAE:
template<class T>
struct is_fusion_map_with_int : boost::mpl::false_ {};
template<class T>
struct is_fusion_map_with_int<BF::map<BF::pair<T, int> > > :
boost::mpl::true_ {};
template<class T>
typename boost::enable_if<is_fusion_map_with_int<T>, T&>::type
inc3(T& arg);
In Christ,
Steven Watanabe
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