Boost logo

Boost Users :

Subject: Re: [Boost-users] [call_traits] Having trouble with call traits combined with type deduction
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2011-12-16 22:34:41


Hi Jeffrey,

>> Is there any way to get type deduction working on a snippet like
>> lousy_attempt (below) to produce my desired_result?
>>
>> template<typename Scalar>
>> typename boost::call_traits<Scalar>::value_type
>> lousy_attempt(typename boost::call_traits<Scalar>::param_type x)
>> {
>>    return x;
>> }
>>
>> int main()
>> {
>>    double y = 5;
>>
>>    // Works...
>>    lousy_attempt<double>(y);
>>
>>    // "No matching function call to lousy_attempt(double&)"
>>    lousy_attempt(y);
>>
>>    return 0;
>> }

> What you're doing can't work, as the compiler cannot deduce a template
> parameter based on matching to a nested type.

Ah.

> If you really want this effect, you can use Boost.EnableIf...

That snippet was a drastically simplified version of some large code.
The enable_if mechanism makes sense but will be a painful burden.

> But I would generally recommend to just use T const &.

I'll keep with your recommendation.

Thank you for the excellent explanation,
Rhys


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