I want to write some functions that take an Object as one of their arguments, whether by lvalue or rvalue ref doesn't matter - but definitely not by value and definitely only an Object. It seems like I have two options for this:
void foo(Object& o) { // stuff } void foo(Object&& o) { foo(o); } // this is fine for my use-case Or using universal references:
template <typename T, typename U> using decays_to = typename std::is_same<std::decay_t<T>, U>::type; template <typename T> std::enable_if_t<decays_to<T, Object>::value> foo(T&& o) { // same stuff as before } But the first option involves writing twice as many functions as I need, and the second option involves writing a bunch of template stuff which is seems like overkill to me (I kind of read that as accept anything for o - oh just kidding, really just an Object).
Is there a better way to solve this or am I just pretty much stuck with whichever one of these I feel less meh about?
void foo(Object const& o)suffice? It will accept both r-value and l-value, but it isconst.std::remove_const_t<std::remove_reference_t<T>>would be a better choice thanstd::decay_t<T>sincedecay_thas the side effect of performing function-to-pointer and array-to-pointer conversions.