Boost logo

Boost Users :

Subject: Re: [Boost-users] Optionally enforce const correctness in template argument deduction - Solved, thanks!
From: er (erwann.rogard_at_[hidden])
Date: 2009-01-18 00:25:21


Steven Watanabe wrote:
> AMDG
>
> er wrote:
>> The example below illustrates my intent, but obviously it's not the
>> right approach... so I'm hoping someone has a suggestion.
>>
>> template<typename X>
>> struct enforce_constness{ typedef add_reference<const X> type; };
>>
>> template<template<typename> class T = enforce_constness>
>> struct A{
>>
>> template<typename X>
>> void operator()(typename T<X>::type x)const{
>> // Under default I'd like const X&
>> };
>>
>> }
>>
>> X x; A<> a; a(x);
>>
>> no match for call to (A<T>)(X&)
>
> It's impossible to deduce what the template parameter should be.
>
> The easiest way is to use a forwarding function that optionally adds const.
> template<typename X>
> void call_impl(X& x) const;
>
> template<typename X>
> void operator()(const X& x) { return(call_impl(x)); }
> template<typename X>
> void operator()(X& x) { return(call_impl(static_cast<typename
> T<X>::type>(x))); }

Thanks!

>
> BTW, your subject line is a bit misleading because this has nothing to
> do with ADL
>
> 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