Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.tuple.h
Go to the documentation of this file.
1
29#ifndef RW_20_TUPLE_H_INCLUDED
30#define RW_20_TUPLE_H_INCLUDED
31
32#include <ostream> // for std::ostream
33#include <tuple>
34#include <type_traits> // for std::decay
35#include <utility> // for std::move
36
37
38// user-defined class for tuple testing (similar to UserClass)
39
41{
42
43 int value_; // some arbitrary value
44
45public:
46
47 // types
48
49 typedef int value_type;
50 typedef unsigned size_type;
51
52 struct count_type // number of constructors/operators called
53 {
61 };
62
63 static count_type actual; // since last reset()
64 static count_type expect; // modified by expect()
65
66
67 // constructors
68
70 : value_ () { ++actual.dflt_ctor; }
71
73 : value_ (src.value_) { ++actual.copy_ctor; }
74
75#if !defined _RWSTD_NO_RVALUE_REFERENCES
76
78 : value_ (std::move (src.value_))
79 { ++actual.move_ctor; }
80
81 // Requires: U is convertible to `value_type'.
82 template <class U >
83 explicit UserDefined (U&& u)
84 : value_ (std::move (u)) { ++actual.tmpl_ctor; }
85
86#endif // !defined _RWSTD_NO_RVALUE_REFERENCES
87
88
89 // assignment
90
92 {
93 value_ = src.value_;
95 return *this;
96 }
97
98 template <class U>
100 {
101 value_ = src;
103 return *this;
104 }
105
106#if !defined _RWSTD_NO_RVALUE_REFERENCES
107
109 {
110 value_ = std::move (src.value_);
112 return *this;
113 }
114
115#endif // !defined _RWSTD_NO_RVALUE_REFERENCES
116
117
118 // accessors
119
120 value_type value () const { return value_; }
121
122
123 // testing
124
125 static void reset ()
126 {
129 actual.tmpl_asgn = 0;
130
133 expect.tmpl_asgn = 0;
134 }
135
136
137 // implicit value_type conversion?
138};
139
141UserDefined::actual = { 0, 0, 0, 0, 0, 0, 0 };
142
144UserDefined::expect = { 0, 0, 0, 0, 0, 0, 0 };
145
146inline bool
148{
149 return lhs.value () == rhs.value ();
150}
151
152inline bool
154{
155 return lhs.value () < rhs.value ();
156}
157
158
160// tuple names
161
162template <class T>
163struct type_name_ { static const char* value; };
164
165#define TYPE_NAME(T) \
166template <> const char* type_name_<T>::value = #T;
167
168TYPE_NAME (std::tuple<>)
169TYPE_NAME (std::tuple<int>)
170TYPE_NAME (std::tuple<const int>)
171TYPE_NAME (std::tuple<int&>)
172TYPE_NAME (std::tuple<std::tuple<int> >)
173TYPE_NAME (std::tuple<UserDefined>)
174
175#undef TYPE_NAME
176#define TYPE_NAME(T, S) \
177template <> const char* type_name_<T>::value = S;
178
179#undef TUPLE
180#define TUPLE std::tuple<long, const char*>
181TYPE_NAME (TUPLE, "std::tuple<long, const char*>")
182
183#undef TUPLE
184#define TUPLE \
185std::tuple<bool, char, int, double, void*, UserDefined>
186TYPE_NAME (TUPLE, "std::tuple<bool, char, int, double, void*, " \
187 "UserDefined>")
188
189#undef TUPLE
190
191#undef TYPE_NAME
192#define TYPE_NAME(T) type_name_<T>::value
193
194
196// formatting specifiers
197
198template <class T>
199struct fmt_spec { static const char* value; };
200
201#define FMT_SPEC(T, S) \
202template <> const char* fmt_spec<T>::value = #S;
203
204FMT_SPEC (bool, %b)
205FMT_SPEC (char, %c)
206FMT_SPEC (int, %d)
207FMT_SPEC (unsigned, %u)
208FMT_SPEC (long, %ld)
209FMT_SPEC (float, %f)
210FMT_SPEC (double, %f)
211FMT_SPEC (char*, %s)
212FMT_SPEC (char const*, %s)
213FMT_SPEC (void*, %p)
214FMT_SPEC (void const*, %p)
215
216#undef DECAY
217#define DECAY(T) typename std::decay<T>::type
218
219// ignore cv-qualifiers and references
220#undef FMT_SPEC
221#define FMT_SPEC(T) fmt_spec<DECAY (T)>::value
222
223
224#endif // define RW_20_TUPLE_H_INCLUDED
#define rhs
Definition 17.names.cpp:536
#define u
Definition 17.names.cpp:137
#define d
Definition 17.names.cpp:115
#define f
Definition 17.names.cpp:119
#define lhs
Definition 17.names.cpp:489
#define c
Definition 17.names.cpp:111
#define b
Definition 17.names.cpp:110
#define s
#define p
Definition 17.names.cpp:132
#define U
Definition 17.names.cpp:164
bool operator==(const UserDefined &lhs, const UserDefined &rhs)
Definition 20.tuple.h:147
#define FMT_SPEC(T, S)
Definition 20.tuple.h:201
#define TUPLE
Definition 20.tuple.h:180
#define TYPE_NAME(T)
Definition 20.tuple.h:165
bool operator<(const UserDefined &lhs, const UserDefined &rhs)
Definition 20.tuple.h:153
T value(const T &val)
static count_type expect
Definition 20.tuple.h:144
UserDefined(U &&u)
Definition 20.tuple.h:83
static void reset()
Definition 20.tuple.h:125
unsigned size_type
Definition 20.tuple.h:50
UserDefined(UserDefined &&src)
Definition 20.tuple.h:77
value_type value() const
Definition 20.tuple.h:120
int value_type
Definition 20.tuple.h:49
static count_type actual
Definition 20.tuple.h:141
UserDefined & operator=(const UserDefined &src)
Definition 20.tuple.h:91
UserDefined(const UserDefined &src)
Definition 20.tuple.h:72
Definition json.h:5363
static const char * value
Definition 20.tuple.h:163