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 int numberOfElements = 42;
29 struct TestIncomplete;
59 static_assert(!IsDereferencable<string>::value,
"IsDereferencable: negative case");
60 static_assert(!IsDereferencable<int>::value,
"IsDereferencable: negative case");
61 static_assert(IsDereferencable<string *>::value,
"IsDereferencable: positive case");
62 static_assert(IsDereferencable<int *>::value,
"IsDereferencable: positive case");
63 static_assert(IsDereferencable<unique_ptr<string>>::value,
"IsDereferencable: positive case");
64 static_assert(IsDereferencable<shared_ptr<string>>::value,
"IsDereferencable: positive case");
65 static_assert(!IsDereferencable<weak_ptr<string>>::value,
"IsDereferencable: positive case");
67 static_assert(!IsIteratable<int>::value,
"IsIterator: negative case");
68 static_assert(!IsIteratable<SomeStruct>::value,
"IsIterator: negative case");
69 static_assert(IsIteratable<string>::value,
"IsIterator: positive case");
70 static_assert(IsIteratable<vector<int>>::value,
"IsIterator: positive case");
71 static_assert(IsIteratable<list<string>>::value,
"IsIterator: positive case");
72 static_assert(IsIteratable<map<string, string>>::value,
"IsIterator: positive case");
73 static_assert(IsIteratable<initializer_list<double>>::value,
"IsIterator: positive case");
74 static_assert(!HasSize<SomeStruct>::value,
"HasSize: negative case");
75 static_assert(!HasSize<forward_list<SomeStruct>>::value,
"HasSize: negative case");
76 static_assert(HasSize<vector<SomeStruct>>::value,
"HasSize: positive case");
77 static_assert(HasSize<string>::value,
"HasSize: positive case");
78 static_assert(HasSize<CountableStruct>::value,
"HasSize: positive case");
79 static_assert(!IsReservable<list<SomeStruct>>::value,
"HasSize: negative case");
80 static_assert(IsReservable<vector<SomeStruct>>::value,
"HasSize: positive case");
81 static_assert(HasOperatorBool<
function<
void(
void)>>::value,
"HasOperatorBool: positive case");
82 static_assert(!HasOperatorBool<SomeStruct>::value,
"HasOperatorBool: negative case");
85 static_assert(!
IsCString<
int[]>::value,
"IsCString: negative case");
87 static_assert(
IsCString<
char[]>::value,
"IsCString: positive case");
113 CPPUNIT_TEST(testDereferenceMaybe);
114 CPPUNIT_TEST_SUITE_END();
124 void testDereferenceMaybe();
134 const auto someString =
"foo"s;
135 const auto someSmartPointer = make_unique<string>(
"foo");
constexpr auto & dereferenceMaybe(T &value)
Dereferences the specified value if possible; otherwise just returns value itself.
void testDereferenceMaybe()
Tests whether a smart pointer to a string can be treated like a normal string through the use of dere...
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 based on the specified.
Evaluates to Bool<true> if the specified type is complete; if the type is only forward-declared it ev...
Evaluates to Bool<true> if all specified conditions are true; otherwise evaluates to Bool<false>.
Evaluates to Bool<true> if the specified type is based on one of the specified templates; otherwise e...
CPPUNIT_TEST_SUITE_REGISTRATION(TraitsTest)
Evaluates to Bool<true> if the specified type is a C-string (char * or const char *); otherwise evalu...
constexpr CountableStruct someStruct
Evaluates to Bool<true> if the specified type is none of the specified types; otherwise evaluates to ...
Evaluates to Bool<true> if at least one of the specified conditions is true; 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 none of the specified conditions are true; otherwise evaluates to Bool<fal...
Contains traits for conveniently exploiting SFINAE.
The TraitsTest class tests parts of the Traits namespace which can not be evaluated at compile-time.
Wraps a static boolean constant.