1

Perfect forwarding is great and all. But what do I do if I want to not perfectly forward and instead just overload, on something that happens to be a templated type?

template<typename T> void foo(T&& ref); template<typename T> void foo(const T& ref); 

Won't work because the first overload will invoke perfect forwarding. I'd really like behaviour very similar to if the first was a normal lvalue reference- where T will always be a value type.

1 Answer 1

3
#include <type_traits> template<typename T> typename std::enable_if < !std::is_reference<T>::value, void >::type foo(T&& ref) {} template<typename T> void foo(const T& ref) {} 
Sign up to request clarification or add additional context in comments.

2 Comments

I never think of the SFINAE solution, because MSVC's support sucks. Thanks :)
I don't know if support is better if you move the enable_if from the return type to the argument list?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.