Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.tuple.creation.cpp
Go to the documentation of this file.
1
29#include <rw_driver.h>
30
31// compile out all test code if extensions disabled
32#if !defined(_RWSTD_NO_EXT_CXX_0X) \
33 && !defined(_RWSTD_NO_RVALUE_REFERENCES)
34
35#include <functional> // for reference_wrapper
36#include <tuple>
37
38#include "20.tuple.h"
39
40
42typedef std::reference_wrapper<int> IntRefWrap;
43
44static void
45test_make_tuple ()
46{
47 rw_info (0, __FILE__, __LINE__, "make_tuple");
48
49 std::tuple<int> it1 = std::make_tuple (1);
50
51 int i = 2;
52 std::tuple<int, int> it2 = std::make_tuple (1, i);
53
54 const int j = 3;
55 std::tuple<int, int, int> it3 = std::make_tuple (1, i, j);
56
57 std::tuple<int&> rt1 = std::make_tuple (std::ref (i));
58
59 std::tuple<const int&> rt2 = std::make_tuple (std::cref (i));
60}
61
62
64#include <cstring>
65
66static void
67test_tie ()
68{
69 rw_info (0, __FILE__, __LINE__, "tie");
70
71 int i = 0; double d = 0.0; const char* s = 0;
72 std::tie (i, std::ignore, s)
73 = std::make_tuple (256, 3.14159, "string");
74
75 rw_assert (i == 256, __FILE__, __LINE__,
76 "i == 256, got false, expected true");
77 rw_assert (d == 0.0, __FILE__, __LINE__,
78 "d == 0.0, got false, expected true");
79 rw_assert (0 == std::strcmp (s, "string"), __FILE__, __LINE__,
80 "s == \"string\", got false, expected true");
81}
82
83
85static void
86test_tuple_cat ()
87{
88 rw_info (0, __FILE__, __LINE__, "tuple_cat");
89
90#define FirstHalf bool, char, int, double
91#define SecondHalf void*, UserDefined
92
93 typedef std::tuple<FirstHalf> FirstTuple;
94 FirstTuple t1 (true, 'a', 256, 3.14159);
95
96 typedef std::tuple<SecondHalf> SecondTuple;
97 SecondTuple t2 (&t1, UserDefined ());
98
99 typedef std::tuple<FirstHalf, SecondHalf> WholeTuple;
100 //WholeTuple t3 (tuple_cat (t1, t2));
101}
102
103
105static int
106run_test (int /*argc*/, char* /*argv*/ [])
107{
108 const void* p = _RWSTD_STATIC_CAST (const void*, &std::ignore);
110
111 test_make_tuple ();
112 test_tie ();
113 test_tuple_cat ();
114
115 return 0;
116}
117
118#else // _RWSTD_NO_EXT_CXX_0X || _RWSTD_NO_RVALUE_REFERENCES
119
120static int
121run_test (int, char*[])
122{
123#if defined (_RWSTD_NO_EXT_CXX_0X)
124
125 rw_warn (0, 0, __LINE__,
126 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
127
128#elif defined (_RWSTD_NO_RVALUE_REFERENCES)
129
130 rw_warn (0, 0, __LINE__,
131 "test disabled because _RWSTD_NO_RVALUE_REFERENCES is "
132 "defined");
133
134#endif
135
136 return 0;
137}
138
139#endif // _RWSTD_NO_EXT_CXX_0X || _RWSTD_NO_RVALUE_REFERENCES
140
141/*extern*/ int
142main (int argc, char* argv [])
143{
144 return rw_test (argc, argv, __FILE__,
145 "[tuple.creation]",
146 "20.3.1.3 Tuple creation functions",
147 run_test, "", 0);
148}
149
#define i
Definition 17.names.cpp:126
#define d
Definition 17.names.cpp:115
#define t1
Definition 17.names.cpp:243
#define t2
Definition 17.names.cpp:269
#define j
Definition 17.names.cpp:127
#define s
#define p
Definition 17.names.cpp:132
std::reference_wrapper< int > IntRefWrap
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647