To build the perfect answer on Jarod42, if you want to preserve the design of the main function template, you can decide based on the type of universal reference parameter deduced:
#include <iostream> #include <type_traits> struct A { template <typename T> // T is either U or U & void func(T && x) { func_impl<T>(std::forward<T>(x)); } template <typename U> void func_impl(typename std::remove_reference<U>::type & u) { std::cout << "lvalue\n"; } template <typename U> void func_impl(typename std::remove_reference<U>::type && u) { std::cout << "rvalue\n"; } };
Kerrek SB
source share