My question revolves around the code below:
template<typename T>
static void whatever(T&& container) {
typename T::value_type x;
std::cout << x << std::endl;
}
struct something {
using value_type = int;
const char* name;
};
int main() {
whatever(something{}); // passes by rvalue, perfectly fine.
something x;
whatever(x); // deduces the type as something& and complains ::value_type doesn't exist.
return 0;
}
Now if I provide an overload to that whatever method that takes a reference as well.
template<typename T>
static void whatever(T& container);
The problem would go away but I have the exact same code for both methods and I'm wondering if there is a nice way to put this all into one method.
This is just an example code I came up with to frame the question.