Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
meta-utils-test.cpp
Go to the documentation of this file.
1/*
2 MetaUtils(Test) - check some simple type trait helpers
3
4 Copyright (C)
5 2011, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/symbol.hpp"
20#include "lib/test/run.hpp"
21#include "lib/meta/util.hpp"
22#include "lib/meta/typelist.hpp"
23#include "lib/hetero-data.hpp"
25
26#include <string>
27#include <array>
28#include <tuple>
29
30namespace lib {
31namespace meta {
32namespace test {
33
34 using std::string;
35 using std::array;
36 using std::tuple;
37 using std::pair;
38
39
40
41
42 /*********************************************************************/
49 class MetaUtils_test : public Test
50 {
51 void
60
61
68 void
70 {
71 CHECK (sizeof(Yes_t) != sizeof (No_t));
72
73 CHECK (sizeof(Yes_t) == sizeof (probe (1)));
74 CHECK (sizeof(Yes_t) == sizeof (probe (1L))); // conversion long -> int
75 CHECK (sizeof(Yes_t) == sizeof (probe ('a'))); // conversion char -> int
76 CHECK (sizeof(No_t) == sizeof (probe ("a"))); // char * can't be converted
77 }
78
79 static Yes_t probe (int);
80 static No_t probe (...);
81
82
83
84 void
86 {
88
89 struct Lunatic
90 : Test
91 {
92 virtual void run (Arg) {}
93 }
94 lunatic;
95 cout << typeStr(lunatic) << endl;
96 cout << typeStr(&lunatic) << endl;
97 cout << typeStr((Test &)lunatic) << endl;
98 cout << typeStr((Test *) &lunatic) << endl;
99 cout << typeStr(&Lunatic::run) << endl;
100 }
101
102
103
104 //-------------------------------------------------TEST-types--
105 class SubString : public string
106 {
107 public:
108 SubString() : string("sublunar") { }
109 };
110
111 class Something { };
112
114 {
115 operator string() { return "No such thing"; }
116 };
117
119 {
120 operator SubString() { return SubString(); }
121 };
122
123 class SomehowSubSub : public SomehowSubtle { };
124 //-------------------------------------------------TEST-types--
125
126 template<typename TY>
127 static bool
129 {
131 }
132
133 void
135 {
136 CHECK ( can_convert (string("inline string")));
137 CHECK ( can_convert ("char literal"));
138 CHECK (!can_convert (23.34));
139 CHECK (!can_convert (23));
140 CHECK (!can_convert (1L));
141
142 string str("mhm");
143 string & str_ref (str);
144 string const& str_const_ref (str);
145 string * str_ptr = &str;
146
147 CHECK ( can_convert (str));
152
157 SubString const& subRef(subsub);
158
159 CHECK ( can_convert (sub));
164 }
165
166
167
168 //-------------------------------------------------TEST-types--
170 ,uint
171 ,int64_t
172 ,uint64_t
173 >::List;
174
175 using EmptyList = Nil;
176 //-------------------------------------------------TEST-types--
177
178
179 void
186 };
187
188
190 LAUNCHER (MetaUtils_test, "unit meta");
191
192
193
194}}} // namespace lib::meta::test
Trait template for detecting a typelist type.
static bool can_convert(TY const &)
Types< int,uint,int64_t,uint64_t >::List TheList
Helpers typically used while writing tests.
Maintain a chained sequence of heterogeneous data blocks without allocation.
unsigned int uint
Definition integral.hpp:29
Simple and lightweight helpers for metaprogramming and type detection.
std::string typeStr(TY const *obj=nullptr) noexcept
failsafe human readable type display
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition meta/util.hpp:99
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
»Empty« mark
Definition typelist.hpp:82
variadic sequence of types
Definition typelist.hpp:102
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
detect possibility of a conversion to string.
Marker types to indicate a literal string and a Symbol.
A template metaprogramming technique for manipulating collections of types.