C++ Utilities  4.14.1
Useful C++ classes and routines 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 <forward_list>
4 #include <list>
5 #include <map>
6 #include <string>
7 #include <vector>
8 
9 using namespace std;
10 using namespace Traits;
11 
12 struct SomeStruct {
13  string foo;
14  int bar;
15 };
16 
19  size_t size() const;
20 };
21 
22 struct TestIncomplete;
23 
24 static_assert(!Bool<false>::value, "Bool<false>");
25 static_assert(Bool<true>::value, "Bool<true>");
26 static_assert(!Not<Bool<true>>::value, "Not");
27 static_assert(!Any<Bool<false>, Bool<false>>::value, "Any: negative case");
28 static_assert(Any<Bool<true>, Bool<false>>::value, "Any: positive case");
29 static_assert(!All<Bool<true>, Bool<false>>::value, "All: negative case");
30 static_assert(All<Bool<true>, Bool<true>>::value, "All: positive case");
31 
32 static_assert(!IsSpecializationOf<string, basic_stringbuf>::value, "IsSpecializationOf: negative case");
33 static_assert(IsSpecializationOf<string, basic_string>::value, "IsSpecializationOf: positive case");
34 
35 static_assert(!IsIteratable<int>::value, "IsIterator: negative case");
36 static_assert(!IsIteratable<SomeStruct>::value, "IsIterator: negative case");
37 static_assert(IsIteratable<string>::value, "IsIterator: positive case");
38 static_assert(IsIteratable<vector<int>>::value, "IsIterator: positive case");
39 static_assert(IsIteratable<list<string>>::value, "IsIterator: positive case");
40 static_assert(IsIteratable<map<string, string>>::value, "IsIterator: positive case");
41 static_assert(IsIteratable<initializer_list<double>>::value, "IsIterator: positive case");
42 static_assert(!HasSize<SomeStruct>::value, "HasSize: negative case");
43 static_assert(!HasSize<forward_list<SomeStruct>>::value, "HasSize: negative case");
44 static_assert(HasSize<vector<SomeStruct>>::value, "HasSize: positive case");
45 static_assert(HasSize<string>::value, "HasSize: positive case");
46 static_assert(HasSize<CountableStruct>::value, "HasSize: positive case");
47 static_assert(!IsReservable<list<SomeStruct>>::value, "HasSize: negative case");
48 static_assert(IsReservable<vector<SomeStruct>>::value, "HasSize: positive case");
49 
50 static_assert(!IsCString<string>::value, "IsCString: negative case");
51 static_assert(!IsCString<int[]>::value, "IsCString: negative case");
52 static_assert(!IsCString<int *>::value, "IsCString: negative case");
53 static_assert(IsCString<char[]>::value, "IsCString: positive case");
54 static_assert(IsCString<char *>::value, "IsCString: positive case");
55 static_assert(IsCString<const char *>::value, "IsCString: positive case");
56 static_assert(!IsString<int *>::value, "IsString: negative case");
57 static_assert(!IsString<stringstream>::value, "IsString: negative case");
58 static_assert(IsString<const char *>::value, "IsString: positive case");
59 static_assert(IsString<string>::value, "IsCString: positive case");
60 static_assert(IsString<u16string>::value, "IsCString: positive case");
61 
62 static_assert(!IsComplete<TestIncomplete>::value, "IsComplete: negative case");
63 static_assert(IsComplete<CountableStruct>::value, "IsComplete: positive case");
string foo
Definition: traitstests.cpp:13
STL namespace.
Contains traits for conveniently exploiting SFINAE.
Definition: traits.h:8