1 #include "../misc/traits.h"
2 #include "../tests/testutils.h"
4 #include <cppunit/TestFixture.h>
5 #include <cppunit/extensions/HelperMacros.h>
7 #include <forward_list>
17 using namespace CPPUNIT_NS;
25 struct CountableStruct {
26 int numberOfElements = 42;
30 struct TestIncomplete;
64 static_assert(!IsDereferencable<string>::value,
"IsDereferencable: negative case");
65 static_assert(!IsDereferencable<int>::value,
"IsDereferencable: negative case");
66 static_assert(IsDereferencable<string *>::value,
"IsDereferencable: positive case");
67 static_assert(IsDereferencable<int *>::value,
"IsDereferencable: positive case");
68 static_assert(IsDereferencable<unique_ptr<string>>::value,
"IsDereferencable: positive case");
69 static_assert(IsDereferencable<shared_ptr<string>>::value,
"IsDereferencable: positive case");
70 static_assert(!IsDereferencable<weak_ptr<string>>::value,
"IsDereferencable: positive case");
72 static_assert(!IsIteratable<int>::value,
"IsIterator: negative case");
73 static_assert(!IsIteratable<SomeStruct>::value,
"IsIterator: negative case");
74 static_assert(IsIteratable<string>::value,
"IsIterator: positive case");
75 static_assert(IsIteratable<vector<int>>::value,
"IsIterator: positive case");
76 static_assert(IsIteratable<list<string>>::value,
"IsIterator: positive case");
77 static_assert(IsIteratable<map<string, string>>::value,
"IsIterator: positive case");
78 static_assert(IsIteratable<initializer_list<double>>::value,
"IsIterator: positive case");
79 static_assert(!HasSize<SomeStruct>::value,
"HasSize: negative case");
80 static_assert(!HasSize<forward_list<SomeStruct>>::value,
"HasSize: negative case");
81 static_assert(HasSize<vector<SomeStruct>>::value,
"HasSize: positive case");
82 static_assert(HasSize<string>::value,
"HasSize: positive case");
83 static_assert(HasSize<CountableStruct>::value,
"HasSize: positive case");
84 static_assert(!IsReservable<list<SomeStruct>>::value,
"HasSize: negative case");
85 static_assert(IsReservable<vector<SomeStruct>>::value,
"HasSize: positive case");
86 static_assert(HasOperatorBool<
function<
void(
void)>>::value,
"HasOperatorBool: positive case");
87 static_assert(!HasOperatorBool<SomeStruct>::value,
"HasOperatorBool: negative case");
90 static_assert(!
IsCString<
int[]>::value,
"IsCString: negative case");
92 static_assert(
IsCString<
char[]>::value,
"IsCString: positive case");
118 CPPUNIT_TEST(testDereferenceMaybe);
119 CPPUNIT_TEST_SUITE_END();
129 void testDereferenceMaybe();
139 auto someString =
"foo"s;
140 auto someSmartPointer = make_unique<string>(
"foo");
The TraitsTest class tests parts of the Traits namespace which can not be evaluated at compile-time.
void testDereferenceMaybe()
Tests whether a smart pointer to a string can be treated like a normal string through the use of dere...
Contains traits for conveniently exploiting SFINAE.
constexpr auto & dereferenceMaybe(T &&value)
Dereferences the specified value if possible; otherwise just returns value itself.
Evaluates to Bool<true> if all specified conditions are true; otherwise evaluates to Bool<false>.
Evaluates to Bool<true> if at least one of the specified conditions is true; otherwise evaluates to B...
Wraps a static boolean constant.
Evaluates to Bool<true> if the specified type is any of the specified types; otherwise evaluates to B...
Evaluates to Bool<true> if the specified type is a C-string (char * or const char *); otherwise evalu...
Evaluates to Bool<true> if the specified type is complete; if the type is only forward-declared it ev...
Evaluates to Bool<true> if the specified type is none of the specified types; otherwise evaluates to ...
Evaluates to Bool<true> if the specified type is based on the specified template; otherwise evaluates...
Evaluates to Bool<true> if the specified type is based on one of the specified templates; otherwise e...
Evaluates to Bool<true> if the specified type is a standard string, standard string view or C-string ...
Evaluates to Bool<true> if none of the specified conditions are true; otherwise evaluates to Bool<fal...
CPPUNIT_TEST_SUITE_REGISTRATION(TraitsTest)
constexpr CountableStruct someStruct