Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
IsContainer
//Title of this code #include <iostream> #include <vector> struct Con { typedef int iterator; iterator begin(); iterator end(); }; template<class T> struct ContainerUser { typedef typename T::iterator iterator; }; template<class T> struct IsContainer { private: class yes { }; class no { yes no[2]; }; template<class A, A, A> struct is_of_type; template<class E> static yes test_value(is_of_type<typename E::iterator(E::*)(), &E::begin, &E::end>*); template<class E> static no test_value(...); public: enum { value = sizeof(test_value<T>(nullptr)) == sizeof(yes) }; }; int main() { typedef int* A; typedef std::vector<int> V; std::cout<<IsContainer<bool>::value<<'\n'; std::cout<<IsContainer<A>::value<<'\n'; std::cout<<IsContainer<V>::value<<'\n'; std::cout<<IsContainer<Con>::value<<'\n'; ContainerUser<Con> b; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
my override
First
Namespace scope qualifier
test C++ register
ternary test
the usual name hiding rules do apply with using directives
Store Information in Structure and Display it
Linker error while passing constexpr variable as const &
return reference (clang)
hello,world !ssn2019
stackse - search stackoverflow differently
Please log in to post a comment.