Most of the work is already done for you by the stdlib, you just need a function wrapper:
template <typename T>
constexpr bool is_lvalue(T&&) {
return std::is_lvalue_reference<T>{};
}
in the case you pass a std::string
lvalue then T
will deduce to std::string&
or const std::string&
, for rvalues it will deduce to std::string
Note that Yakk's answer will return a different type, which allows for more flexibility and you should read that answer and probably use it instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…