0

It's possible that give std::vector<T> e.g to function by forwarding reference? I know that

template<typename T>
void f(const std::vector<T>&&){} // is rvalue
template<typename T>
void f(const std::vector<T>&){} // is lvalue

but how I can make function for lvalue and rvalue (with std::vector as parametr)?

21koizyd
  • 1,843
  • 12
  • 25

1 Answers1

1

I think you want

// traits for detecting std::vector
template <typename> struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template<typename T>
std::enable_if_t<is_std_vector<std::decay_t<T>>::value>
f(T&&); // Take any std::vector
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • I though about this but I had make sure. Thanks. – 21koizyd Jul 03 '17 at 23:13
  • Okey, I was implemented that but i have problem with return value from function if I want, i tried `typename std::enable_if_t>::value>::type`, but doesn't work in this case. Type of course (`T` - input) – 21koizyd Jul 04 '17 at 02:03