Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.forward.cpp
Go to the documentation of this file.
1
29#include <rw_driver.h>
30#include <rw/_defs.h>
31
32// compile out all test code if extensions disabled
33#ifndef _RWSTD_NO_EXT_CXX_0X
34
35#include <rw/_forward.h>
36#include <rw/_meta_rel.h>
37#include <rw/_static_assert.h>
38
39
40
41struct Foo
42{
43 Foo (int& ) { }
44};
45
46
47static void
48test_identity ()
49{
50 rw_info (0, __FILE__, __LINE__, "std::identity<T> class template");
51
52 typedef std::identity<Foo> FooIdent;
53 typedef std::identity<Foo>::type FooIdentType;
54
55 _RWSTD_STATIC_ASSERT ((_RW::__rw_is_same<Foo, FooIdentType>::value),
56 "is_same<Foo, FooIdentType>::value is false, "
57 "expected true");
58
59 int i = 1;
60 FooIdent foo_ident;
61 Foo foo = foo_ident (i);
62
63}
64
65
67#ifndef _RWSTD_NO_RVALUE_REFERENCES
68
69// using example from standard as a test case
70
71template <class Type>
73{
74 Type* ptr_;
75
76public:
77 shared_ptr (Type* ptr): ptr_ (ptr) { }
78 ~shared_ptr () { delete ptr_; }
79};
80
81template <class Type, class AType>
83{
84 return shared_ptr<Type> (new Type (std::forward<AType> (at)));
85}
86
87
89static void
90test_forward ()
91{
92 rw_info (0, __FILE__, __LINE__, "std::forward() function");
93
94}
95
96
98static void
99test_move ()
100{
101 rw_info (0, __FILE__, __LINE__, "std::move() function");
102
103}
104
105#endif // _RWSTD_NO_RVALUE_REFERENCES
106
107
109static int
110run_test (int /*unused*/, char* /*unused*/ [])
111{
112 test_identity ();
113
114#if !defined _RWSTD_NO_RVALUE_REFERENCES
115
116 test_forward ();
117 test_move ();
118
119#else // no rvalue references
120
121 rw_warn (0, 0, __LINE__,
122 "No compiler support for rvalue references; tests disabled.");
123
124#endif // !defined _RWSTD_NO_RVALUE_REFERENCES
125
126 return 0;
127}
128
129#else // !_RWSTD_NO_EXT_CXX_0X
130
131static int run_test (int, char*[])
132{
133 rw_warn (0, 0, __LINE__,
134 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
135 return 0;
136}
137
138#endif // !_RWSTD_NO_EXT_CXX_0X
139
140/*extern*/ int
141main (int argc, char* argv [])
142{
143 return rw_test (argc, argv, __FILE__,
144 "[forward]", "20.2.2 forward/move helpers",
145 run_test, "", 0);
146}
147
#define i
Definition 17.names.cpp:126
#define ptr
Definition 17.names.cpp:525
shared_ptr< Type > factory(AType &&at)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define _RWSTD_STATIC_ASSERT(Cond, Mesg)
shared_ptr(Type *ptr)
_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_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647
Foo(int &)