I'm looking for a way to detect if a template class has the methods begin, end and resize.
I tried a modified version of this answer:
#include <iostream>
#include <vector>
// SFINAE test
template <typename T>
class has_method
{
typedef char one;
struct two { char x[2]; };
template <typename C> static one test( decltype(&C::begin) ) ;
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
int main(int argc, char *argv[])
{
std::cout << has_method<std::vector<int>>::value << std::endl;
return 0;
}
However this prints 0. What is funny is that this will work with cbegin and cend but not with begin, end and resize. User defined classes implementing those methods works fine though.
I've tried this with both g++ and with Visual Studio 19 and I get the same results so this doesn't seem to be related to the compiler or the STL's implementation.