
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 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
(x))); }
Thanks!
BTW, your subject line is a bit misleading because this has nothing to do with ADL
In Christ, Steven Watanabe