Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
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
template specialization inheritance solution
Set sub sequences.
isnan_constexpr
11/18
constructor-is-not-called-in-this-aggregation-class
Tree Traversal and Node
bubble sort
std::function copies
Assignment Operator Example
Dynamic call