rvalue or lvalue (const) reference parameter
c++, c++11, sfinae, universal-reference
Solution
If I understand your question correctly, you wish to have a single function whose parameter is either an rvalue reference (in case an rvalue is provided) or an lvalue reference to `const` (in case an lvalue is provided).
But what would this function do? Well, since it must be able to handle both cases, including the case where an lvalue is provided, it cannot modify its input (at least not the one bound to the `x` parameter) - if it did, it would violate the semantics of the `const` reference.
But then again, if it cannot alter the state of the parameter, there is no reason for allowing an rvalue reference: rather let `x` be an lvalue-reference to `const` all the time. lvalue references to `const` can bind to rvalues, so you will be allowed to pass both rvalues and lvalues.
If the semantics of the function is different based on what is passed, then I would say it makes more sense to write two such functions: one that takes an rvalue reference and one that takes an lvalue reference to `const`.
Problem
I want to pass a parameter(s) (of some concrete type, say `int`) to the member function by r- or l- value (const) reference. My solution is: ``` #include <type_traits> #include <utility> struct F { using desired_parameter_type = int; template< typename X, typename = typename std::enable_if< std::is_same< typename std::decay< X >::type, desired_parameter_type >::value >::type > void operator () (X && x) const { // or even static_assert(std::is_same< typename std::decay< X >::type, desired_parameter_type >::value, ""); std::forward< X >(x); // something useful } }; ``` Another exaple is here http://pastebin.com/9kgHmsVC. But it is too verbose. How to do it in a simpler way? Maybe I should use the superposition of `std::remove_reference` and `std::remove_const` instead of `std::decay`, but there is just a simplification here.