C++ Utilities  4.9.2
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
traitstests.cpp
Go to the documentation of this file.
1 #include "../misc/traits.h"
2 
3 #include <list>
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 using namespace std;
9 using namespace Traits;
10 
11 struct SomeStruct {
12  string foo;
13  int bar;
14 };
15 
16 static_assert(!Bool<false>::value, "Bool<false>");
17 static_assert(Bool<true>::value, "Bool<true>");
18 static_assert(!Not<Bool<true>>::value, "Not");
19 static_assert(!Any<Bool<false>, Bool<false>>::value, "Any: negative case");
20 static_assert(Any<Bool<true>, Bool<false>>::value, "Any: positive case");
21 static_assert(!All<Bool<true>, Bool<false>>::value, "All: negative case");
22 static_assert(All<Bool<true>, Bool<true>>::value, "All: positive case");
23 
24 static_assert(!IsSpecializationOf<string, basic_stringbuf>::value, "IsSpecializationOf: negative case");
25 static_assert(IsSpecializationOf<string, basic_string>::value, "IsSpecializationOf: positive case");
26 
27 static_assert(!IsIteratable<int>::value, "IsIterator: negative case");
28 static_assert(!IsIteratable<SomeStruct>::value, "IsIterator: negative case");
29 static_assert(IsIteratable<string>::value, "IsIterator: positive case");
30 static_assert(IsIteratable<vector<int>>::value, "IsIterator: positive case");
31 static_assert(IsIteratable<list<string>>::value, "IsIterator: positive case");
32 static_assert(IsIteratable<map<string, string>>::value, "IsIterator: positive case");
33 static_assert(IsIteratable<initializer_list<double>>::value, "IsIterator: positive case");
34 
35 static_assert(!IsCString<string>::value, "IsCString: negative case");
36 static_assert(!IsCString<int[]>::value, "IsCString: negative case");
37 static_assert(!IsCString<int *>::value, "IsCString: negative case");
38 static_assert(IsCString<char[]>::value, "IsCString: positive case");
39 static_assert(IsCString<char *>::value, "IsCString: positive case");
40 static_assert(IsCString<const char *>::value, "IsCString: positive case");
41 static_assert(!IsString<int *>::value, "IsString: negative case");
42 static_assert(!IsString<stringstream>::value, "IsString: negative case");
43 static_assert(IsString<const char *>::value, "IsString: positive case");
44 static_assert(IsString<string>::value, "IsCString: positive case");
45 static_assert(IsString<u16string>::value, "IsCString: positive case");
decltype(Detail::isIteratableImpl< T >(0)) IsIteratable
Definition: traits.h:71
string foo
Definition: traitstests.cpp:12
STL namespace.
Contains traits for conveniently exploiting SFINAE.
Definition: traits.h:8