I expect this code will work with vector of vector but it seems to detect the existence of size only for the external vector. Anyone can help?
#include <iostream>
#include <vector>
// SFINAE test
template <typename T>
class has_size
{
typedef char one;
struct two { char x[2]; };
template <typename C> static one test( decltype(&C::size) ) ;
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
int main(int argc, char *argv[])
{
float x=2;
std::cout << typeid(x).name() << '\n';
std::cout << has_size<decltype(x)>::value << std::endl;
std::vector<std::vector<std::vector<float>>> y{};
std::cout << typeid(y).name() << '\n';
std::cout << has_size<decltype(y)>::value << std::endl;
std::cout << typeid(y.at(0)).name() << '\n';
std::cout << has_size<decltype(y.at(0))>::value << std::endl;
std::cout << typeid(y.at(0).at(0)).name() << '\n';
std::cout << has_size<decltype(y.at(0).at(0))>::value << std::endl;
return 0;
}
Below you can find the output:
f 0
St6vectorIS_IS_IfSaIfEESaIS1_EESaIS3_EE 1
St6vectorIS_IfSaIfEESaIS1_EE 0
St6vectorIfSaIfEE 0