e.g. I have a function that can handle const T &
and T &&
values:
template <typename T>
/* ... */ foo(const T &) {
std::cout << "const T & as arg" << std::endl;
}
template <typename T>
/* ... */ foo(T &&) {
std::cout << "T && as arg" << std::endl;
}
Is there a way that I can write a single function, that handles both types automatically? As in:
template <typename T>
/* ... */ bar(T t) {
foo(t);
}
So that:
T a;
bar(a); // Handles as const T &
T b;
bar(std::move(b)); // Handles as T &&
Thank you!