I would like to know if a templated type has a 'push_back' method. I tried this example : Is it possible to write a template to check for a function's existence?
my code :
template <typename T>
class has_push_back
{
typedef char one;
typedef long two;
template <typename C> static one test(char[sizeof(&C::push_back)]);
template <typename C> static two test(...);
public:
enum { value = (sizeof(test<T>(0)) == sizeof(char)) };
};
My call :
template <typename T>
HTTPMessage Serializer::GetHTTPMessage(T varToSerialize)
{
std::cout << has_push_back<T>::value << std::endl;
//some code
}
Unfortunatly I got this error when GetHTTPMessage is called with std::string :
'overloaded-function': illegal sizeof operand
note: see reference to class template instantiation 'has_push_back' being compiled with [ T=std::string ]
I don't understand why it does not compile.