summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities/function.objects/refwrap
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/utilities/function.objects/refwrap')
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/binary.pass.cpp80
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp46
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp58
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp46
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp22
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp45
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp24
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp25
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp27
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp24
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp43
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp52
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp329
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp76
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp68
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/type.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp58
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/unary.pass.cpp78
-rw-r--r--libcxx/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp82
19 files changed, 1220 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/binary.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/binary.pass.cpp
new file mode 100644
index 00000000000..579e81fe69e
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/binary.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// check for deriving from binary_function
+
+#include <functional>
+#include <type_traits>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+class functor2
+ : public std::binary_function<char, int, double>
+{
+};
+
+class functor3
+ : public std::unary_function<int, int>,
+ public std::binary_function<char, int, double>
+{
+public:
+ typedef float result_type;
+};
+
+class functor4
+ : public std::unary_function<int, int>,
+ public std::binary_function<char, int, double>
+{
+public:
+};
+
+struct C
+{
+ typedef int argument_type;
+ typedef int result_type;
+};
+
+int main()
+{
+ static_assert((!std::is_base_of<std::binary_function<int, char, int>,
+ std::reference_wrapper<functor1> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<char, int, double>,
+ std::reference_wrapper<functor2> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<char, int, double>,
+ std::reference_wrapper<functor3> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<char, int, double>,
+ std::reference_wrapper<functor4> >::value), "");
+ static_assert((!std::is_base_of<std::binary_function<int, int, int>,
+ std::reference_wrapper<C> >::value), "");
+ static_assert((!std::is_base_of<std::binary_function<int, int, float>,
+ std::reference_wrapper<float ()> >::value), "");
+ static_assert((!std::is_base_of<std::binary_function<int, int, float>,
+ std::reference_wrapper<float (int)> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<int, int, float>,
+ std::reference_wrapper<float (int, int)> >::value), "");
+ static_assert((!std::is_base_of<std::binary_function<int, int, float>,
+ std::reference_wrapper<float(*)()> >::value), "");
+ static_assert((!std::is_base_of<std::binary_function<int, int, float>,
+ std::reference_wrapper<float(*)(int)> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<int, int, float>,
+ std::reference_wrapper<float(*)(int, int)> >::value), "");
+ static_assert((!std::is_base_of<std::binary_function<C*, int, float>,
+ std::reference_wrapper<float(C::*)()> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<C*, int, float>,
+ std::reference_wrapper<float(C::*)(int)> >::value), "");
+ static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,
+ std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp
new file mode 100644
index 00000000000..df0b55a5d06
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// operator T& () const;
+
+#include <functional>
+#include <cassert>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+template <class T>
+void
+test(T& t)
+{
+ std::reference_wrapper<T> r(t);
+ T& r2 = r;
+ assert(&r2 == &t);
+}
+
+void f() {}
+
+int main()
+{
+ void (*fp)() = f;
+ test(fp);
+ test(f);
+ functor1 f1;
+ test(f1);
+ int i = 0;
+ test(i);
+ const int j = 0;
+ test(j);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp
new file mode 100644
index 00000000000..122716a23a8
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// reference_wrapper& operator=(const reference_wrapper<T>& x);
+
+#include <functional>
+#include <cassert>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+template <class T>
+void
+test(T& t)
+{
+ std::reference_wrapper<T> r(t);
+ T t2 = t;
+ std::reference_wrapper<T> r2(t2);
+ r2 = r;
+ assert(&r2.get() == &t);
+}
+
+void f() {}
+void g() {}
+
+void
+test_function()
+{
+ std::reference_wrapper<void ()> r(f);
+ std::reference_wrapper<void ()> r2(g);
+ r2 = r;
+ assert(&r2.get() == &f);
+}
+
+int main()
+{
+ void (*fp)() = f;
+ test(fp);
+ test_function();
+ functor1 f1;
+ test(f1);
+ int i = 0;
+ test(i);
+ const int j = 0;
+ test(j);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp
new file mode 100644
index 00000000000..721a442d443
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// reference_wrapper(const reference_wrapper<T>& x);
+
+#include <functional>
+#include <cassert>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+template <class T>
+void
+test(T& t)
+{
+ std::reference_wrapper<T> r(t);
+ std::reference_wrapper<T> r2 = r;
+ assert(&r2.get() == &t);
+}
+
+void f() {}
+
+int main()
+{
+ void (*fp)() = f;
+ test(fp);
+ test(f);
+ functor1 f1;
+ test(f1);
+ int i = 0;
+ test(i);
+ const int j = 0;
+ test(j);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp
new file mode 100644
index 00000000000..ba46946aae1
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// reference_wrapper(T&&) = delete;
+
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ std::reference_wrapper<const int> r(3);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp
new file mode 100644
index 00000000000..564a3f77433
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// reference_wrapper(T& t);
+
+#include <functional>
+#include <cassert>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+template <class T>
+void
+test(T& t)
+{
+ std::reference_wrapper<T> r(t);
+ assert(&r.get() == &t);
+}
+
+void f() {}
+
+int main()
+{
+ void (*fp)() = f;
+ test(fp);
+ test(f);
+ functor1 f1;
+ test(f1);
+ int i = 0;
+ test(i);
+ const int j = 0;
+ test(j);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp
new file mode 100644
index 00000000000..f2ffd44e26b
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <ObjectType T> reference_wrapper<const T> cref(const T& t);
+
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ int i = 0;
+ std::reference_wrapper<const int> r = std::cref(i);
+ assert(&r.get() == &i);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp
new file mode 100644
index 00000000000..75875264479
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t);
+
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ const int i = 0;
+ std::reference_wrapper<const int> r1 = std::cref(i);
+ std::reference_wrapper<const int> r2 = std::cref(r1);
+ assert(&r2.get() == &i);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp
new file mode 100644
index 00000000000..86a5696f48c
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <ObjectType T> reference_wrapper<T> ref(T& t);
+
+// Don't allow binding to a temp
+
+#include <functional>
+
+struct A {};
+
+const A source() {return A();}
+
+int main()
+{
+ std::reference_wrapper<const A> r = std::ref(source());
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp
new file mode 100644
index 00000000000..39aa4843a71
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <ObjectType T> reference_wrapper<T> ref(T& t);
+
+#include <functional>
+#include <cassert>
+
+int main()
+{
+ int i = 0;
+ std::reference_wrapper<int> r = std::ref(i);
+ assert(&r.get() == &i);
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp
new file mode 100644
index 00000000000..4033e676f01
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t);
+
+#include <functional>
+#include <cassert>
+
+#include "counting_predicates.hpp"
+
+bool is5 ( int i ) { return i == 5; }
+
+template <typename T>
+bool call_pred ( T pred ) { return pred(5); }
+
+int main()
+{
+ {
+ int i = 0;
+ std::reference_wrapper<int> r1 = std::ref(i);
+ std::reference_wrapper<int> r2 = std::ref(r1);
+ assert(&r2.get() == &i);
+ }
+ {
+ unary_counting_predicate<bool(*)(int), int> cp(is5);
+ assert(!cp(6));
+ assert(cp.count() == 1);
+ assert(call_pred(cp));
+ assert(cp.count() == 1);
+ assert(call_pred(std::ref(cp)));
+ assert(cp.count() == 2);
+ }
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp
new file mode 100644
index 00000000000..551562721e3
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <class... ArgTypes>
+// requires Callable<T, ArgTypes&&...>
+// Callable<T, ArgTypes&&...>::result_type
+// operator()(ArgTypes&&... args) const;
+
+#include <functional>
+#include <cassert>
+
+// member data pointer: cv qualifiers should transfer from argument to return type
+
+struct A_int_1
+{
+ A_int_1() : data_(5) {}
+
+ int data_;
+};
+
+void
+test_int_1()
+{
+ // member data pointer
+ {
+ int A_int_1::*fp = &A_int_1::data_;
+ std::reference_wrapper<int A_int_1::*> r1(fp);
+ A_int_1 a;
+ assert(r1(a) == 5);
+ r1(a) = 6;
+ assert(r1(a) == 6);
+ const A_int_1* ap = &a;
+ assert(r1(ap) == 6);
+ r1(ap) = 7;
+ assert(r1(ap) == 7);
+ }
+}
+
+int main()
+{
+ test_int_1();
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp
new file mode 100644
index 00000000000..a9edf00ee59
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp
@@ -0,0 +1,329 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <class... ArgTypes>
+// requires Callable<T, ArgTypes&&...>
+// Callable<T, ArgTypes&&...>::result_type
+// operator()(ArgTypes&&... args) const;
+
+#include <functional>
+#include <cassert>
+
+int count = 0;
+
+// 1 arg, return void
+
+void f_void_1(int i)
+{
+ count += i;
+}
+
+struct A_void_1
+{
+ void operator()(int i)
+ {
+ count += i;
+ }
+
+ void mem1() {++count;}
+ void mem2() const {++count;}
+};
+
+void
+test_void_1()
+{
+ int save_count = count;
+ // function
+ {
+ std::reference_wrapper<void (int)> r1(f_void_1);
+ int i = 2;
+ r1(i);
+ assert(count == save_count+2);
+ save_count = count;
+ }
+ // function pointer
+ {
+ void (*fp)(int) = f_void_1;
+ std::reference_wrapper<void (*)(int)> r1(fp);
+ int i = 3;
+ r1(i);
+ assert(count == save_count+3);
+ save_count = count;
+ }
+ // functor
+ {
+ A_void_1 a0;
+ std::reference_wrapper<A_void_1> r1(a0);
+ int i = 4;
+ r1(i);
+ assert(count == save_count+4);
+ save_count = count;
+ }
+ // member function pointer
+ {
+ void (A_void_1::*fp)() = &A_void_1::mem1;
+ std::reference_wrapper<void (A_void_1::*)()> r1(fp);
+ A_void_1 a;
+ r1(a);
+ assert(count == save_count+1);
+ save_count = count;
+ A_void_1* ap = &a;
+ r1(ap);
+ assert(count == save_count+1);
+ save_count = count;
+ }
+ // const member function pointer
+ {
+ void (A_void_1::*fp)() const = &A_void_1::mem2;
+ std::reference_wrapper<void (A_void_1::*)() const> r1(fp);
+ A_void_1 a;
+ r1(a);
+ assert(count == save_count+1);
+ save_count = count;
+ A_void_1* ap = &a;
+ r1(ap);
+ assert(count == save_count+1);
+ save_count = count;
+ }
+}
+
+// 1 arg, return int
+
+int f_int_1(int i)
+{
+ return i + 1;
+}
+
+struct A_int_1
+{
+ A_int_1() : data_(5) {}
+ int operator()(int i)
+ {
+ return i - 1;
+ }
+
+ int mem1() {return 3;}
+ int mem2() const {return 4;}
+ int data_;
+};
+
+void
+test_int_1()
+{
+ // function
+ {
+ std::reference_wrapper<int (int)> r1(f_int_1);
+ int i = 2;
+ assert(r1(i) == 3);
+ }
+ // function pointer
+ {
+ int (*fp)(int) = f_int_1;
+ std::reference_wrapper<int (*)(int)> r1(fp);
+ int i = 3;
+ assert(r1(i) == 4);
+ }
+ // functor
+ {
+ A_int_1 a0;
+ std::reference_wrapper<A_int_1> r1(a0);
+ int i = 4;
+ assert(r1(i) == 3);
+ }
+ // member function pointer
+ {
+ int (A_int_1::*fp)() = &A_int_1::mem1;
+ std::reference_wrapper<int (A_int_1::*)()> r1(fp);
+ A_int_1 a;
+ assert(r1(a) == 3);
+ A_int_1* ap = &a;
+ assert(r1(ap) == 3);
+ }
+ // const member function pointer
+ {
+ int (A_int_1::*fp)() const = &A_int_1::mem2;
+ std::reference_wrapper<int (A_int_1::*)() const> r1(fp);
+ A_int_1 a;
+ assert(r1(a) == 4);
+ A_int_1* ap = &a;
+ assert(r1(ap) == 4);
+ }
+ // member data pointer
+ {
+ int A_int_1::*fp = &A_int_1::data_;
+ std::reference_wrapper<int A_int_1::*> r1(fp);
+ A_int_1 a;
+ assert(r1(a) == 5);
+ r1(a) = 6;
+ assert(r1(a) == 6);
+ A_int_1* ap = &a;
+ assert(r1(ap) == 6);
+ r1(ap) = 7;
+ assert(r1(ap) == 7);
+ }
+}
+
+// 2 arg, return void
+
+void f_void_2(int i, int j)
+{
+ count += i+j;
+}
+
+struct A_void_2
+{
+ void operator()(int i, int j)
+ {
+ count += i+j;
+ }
+
+ void mem1(int i) {count += i;}
+ void mem2(int i) const {count += i;}
+};
+
+void
+test_void_2()
+{
+ int save_count = count;
+ // function
+ {
+ std::reference_wrapper<void (int, int)> r1(f_void_2);
+ int i = 2;
+ int j = 3;
+ r1(i, j);
+ assert(count == save_count+5);
+ save_count = count;
+ }
+ // function pointer
+ {
+ void (*fp)(int, int) = f_void_2;
+ std::reference_wrapper<void (*)(int, int)> r1(fp);
+ int i = 3;
+ int j = 4;
+ r1(i, j);
+ assert(count == save_count+7);
+ save_count = count;
+ }
+ // functor
+ {
+ A_void_2 a0;
+ std::reference_wrapper<A_void_2> r1(a0);
+ int i = 4;
+ int j = 5;
+ r1(i, j);
+ assert(count == save_count+9);
+ save_count = count;
+ }
+ // member function pointer
+ {
+ void (A_void_2::*fp)(int) = &A_void_2::mem1;
+ std::reference_wrapper<void (A_void_2::*)(int)> r1(fp);
+ A_void_2 a;
+ int i = 3;
+ r1(a, i);
+ assert(count == save_count+3);
+ save_count = count;
+ A_void_2* ap = &a;
+ r1(ap, i);
+ assert(count == save_count+3);
+ save_count = count;
+ }
+ // const member function pointer
+ {
+ void (A_void_2::*fp)(int) const = &A_void_2::mem2;
+ std::reference_wrapper<void (A_void_2::*)(int) const> r1(fp);
+ A_void_2 a;
+ int i = 4;
+ r1(a, i);
+ assert(count == save_count+4);
+ save_count = count;
+ A_void_2* ap = &a;
+ r1(ap, i);
+ assert(count == save_count+4);
+ save_count = count;
+ }
+}
+
+// 2 arg, return int
+
+int f_int_2(int i, int j)
+{
+ return i+j;
+}
+
+struct A_int_2
+{
+ int operator()(int i, int j)
+ {
+ return i+j;
+ }
+
+ int mem1(int i) {return i+1;}
+ int mem2(int i) const {return i+2;}
+};
+
+void
+testint_2()
+{
+ // function
+ {
+ std::reference_wrapper<int (int, int)> r1(f_int_2);
+ int i = 2;
+ int j = 3;
+ assert(r1(i, j) == i+j);
+ }
+ // function pointer
+ {
+ int (*fp)(int, int) = f_int_2;
+ std::reference_wrapper<int (*)(int, int)> r1(fp);
+ int i = 3;
+ int j = 4;
+ assert(r1(i, j) == i+j);
+ }
+ // functor
+ {
+ A_int_2 a0;
+ std::reference_wrapper<A_int_2> r1(a0);
+ int i = 4;
+ int j = 5;
+ assert(r1(i, j) == i+j);
+ }
+ // member function pointer
+ {
+ int(A_int_2::*fp)(int) = &A_int_2::mem1;
+ std::reference_wrapper<int (A_int_2::*)(int)> r1(fp);
+ A_int_2 a;
+ int i = 3;
+ assert(r1(a, i) == i+1);
+ A_int_2* ap = &a;
+ assert(r1(ap, i) == i+1);
+ }
+ // const member function pointer
+ {
+ int (A_int_2::*fp)(int) const = &A_int_2::mem2;
+ std::reference_wrapper<int (A_int_2::*)(int) const> r1(fp);
+ A_int_2 a;
+ int i = 4;
+ assert(r1(a, i) == i+2);
+ A_int_2* ap = &a;
+ assert(r1(ap, i) == i+2);
+ }
+}
+
+int main()
+{
+ test_void_1();
+ test_int_1();
+ test_void_2();
+ testint_2();
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp
new file mode 100644
index 00000000000..61357a7fa39
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <class... ArgTypes>
+// requires Callable<T, ArgTypes&&...>
+// Callable<T, ArgTypes&&...>::result_type
+// operator()(ArgTypes&&... args) const;
+
+#include <functional>
+#include <cassert>
+
+// 0 args, return int
+
+int count = 0;
+
+int f_int_0()
+{
+ return 3;
+}
+
+struct A_int_0
+{
+ int operator()() {return 4;}
+};
+
+void
+test_int_0()
+{
+ // function
+ {
+ std::reference_wrapper<int ()> r1(f_int_0);
+ assert(r1() == 3);
+ }
+ // function pointer
+ {
+ int (*fp)() = f_int_0;
+ std::reference_wrapper<int (*)()> r1(fp);
+ assert(r1() == 3);
+ }
+ // functor
+ {
+ A_int_0 a0;
+ std::reference_wrapper<A_int_0> r1(a0);
+ assert(r1() == 4);
+ }
+}
+
+// 1 arg, return void
+
+void f_void_1(int i)
+{
+ count += i;
+}
+
+struct A_void_1
+{
+ void operator()(int i)
+ {
+ count += i;
+ }
+};
+
+int main()
+{
+ test_int_0();
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp
new file mode 100644
index 00000000000..8d700508cdc
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// template <class... ArgTypes>
+// requires Callable<T, ArgTypes&&...>
+// Callable<T, ArgTypes&&...>::result_type
+// operator()(ArgTypes&&... args) const;
+
+#include <functional>
+#include <cassert>
+
+// 0 args, return void
+
+int count = 0;
+
+void f_void_0()
+{
+ ++count;
+}
+
+struct A_void_0
+{
+ void operator()() {++count;}
+};
+
+void
+test_void_0()
+{
+ int save_count = count;
+ // function
+ {
+ std::reference_wrapper<void ()> r1(f_void_0);
+ r1();
+ assert(count == save_count+1);
+ save_count = count;
+ }
+ // function pointer
+ {
+ void (*fp)() = f_void_0;
+ std::reference_wrapper<void (*)()> r1(fp);
+ r1();
+ assert(count == save_count+1);
+ save_count = count;
+ }
+ // functor
+ {
+ A_void_0 a0;
+ std::reference_wrapper<A_void_0> r1(a0);
+ r1();
+ assert(count == save_count+1);
+ save_count = count;
+ }
+}
+
+int main()
+{
+ test_void_0();
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/type.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/type.pass.cpp
new file mode 100644
index 00000000000..68e40679814
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/type.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// check for member typedef type
+
+#include <functional>
+#include <type_traits>
+
+class C {};
+
+int main()
+{
+ static_assert((std::is_same<std::reference_wrapper<C>::type,
+ C>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<void ()>::type,
+ void ()>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int* (double*)>::type,
+ int* (double*)>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<void(*)()>::type,
+ void(*)()>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::type,
+ int*(*)(double*)>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::type,
+ int*(C::*)(double*)>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::type,
+ int (C::*)(double*) const volatile>::value), "");
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp
new file mode 100644
index 00000000000..61e0bfa162d
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// Test that reference wrapper meets the requirements of TriviallyCopyable,
+// CopyConstructible and CopyAssignable.
+
+#include <functional>
+#include <type_traits>
+#include <string>
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+class MoveOnly
+{
+ MoveOnly(const MoveOnly&);
+ MoveOnly& operator=(const MoveOnly&);
+
+ int data_;
+public:
+ MoveOnly(int data = 1) : data_(data) {}
+ MoveOnly(MoveOnly&& x)
+ : data_(x.data_) {x.data_ = 0;}
+ MoveOnly& operator=(MoveOnly&& x)
+ {data_ = x.data_; x.data_ = 0; return *this;}
+
+ int get() const {return data_;}
+};
+#endif
+
+
+template <class T>
+void test()
+{
+ typedef std::reference_wrapper<T> Wrap;
+ static_assert(std::is_copy_constructible<Wrap>::value, "");
+ static_assert(std::is_copy_assignable<Wrap>::value, "");
+ // Extension up for standardization: See N4151.
+ static_assert(std::is_trivially_copyable<Wrap>::value, "");
+}
+
+int main()
+{
+ test<int>();
+ test<double>();
+ test<std::string>();
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ test<MoveOnly>();
+#endif
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/unary.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/unary.pass.cpp
new file mode 100644
index 00000000000..528a8f327d9
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/unary.pass.cpp
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// check for deriving from unary_function
+
+#include <functional>
+#include <type_traits>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+class functor2
+ : public std::binary_function<char, int, double>
+{
+};
+
+class functor3
+ : public std::unary_function<int, int>,
+ public std::binary_function<char, int, double>
+{
+public:
+ typedef float result_type;
+};
+
+class functor4
+ : public std::unary_function<int, int>,
+ public std::binary_function<char, int, double>
+{
+public:
+};
+
+struct C
+{
+ typedef int argument_type;
+ typedef int result_type;
+};
+
+int main()
+{
+ static_assert((std::is_base_of<std::unary_function<int, char>,
+ std::reference_wrapper<functor1> >::value), "");
+ static_assert((!std::is_base_of<std::unary_function<char, int>,
+ std::reference_wrapper<functor2> >::value), "");
+ static_assert((std::is_base_of<std::unary_function<int, int>,
+ std::reference_wrapper<functor3> >::value), "");
+ static_assert((std::is_base_of<std::unary_function<int, int>,
+ std::reference_wrapper<functor4> >::value), "");
+ static_assert((!std::is_base_of<std::unary_function<int, int>,
+ std::reference_wrapper<C> >::value), "");
+ static_assert((!std::is_base_of<std::unary_function<int, float>,
+ std::reference_wrapper<float(*)()> >::value), "");
+ static_assert((std::is_base_of<std::unary_function<int, float>,
+ std::reference_wrapper<float (int)> >::value), "");
+ static_assert((!std::is_base_of<std::unary_function<int, float>,
+ std::reference_wrapper<float (int, int)> >::value), "");
+ static_assert((std::is_base_of<std::unary_function<int, float>,
+ std::reference_wrapper<float(*)(int)> >::value), "");
+ static_assert((!std::is_base_of<std::unary_function<int, float>,
+ std::reference_wrapper<float(*)(int, int)> >::value), "");
+ static_assert((std::is_base_of<std::unary_function<C*, float>,
+ std::reference_wrapper<float(C::*)()> >::value), "");
+ static_assert((std::is_base_of<std::unary_function<const volatile C*, float>,
+ std::reference_wrapper<float(C::*)() const volatile> >::value), "");
+ static_assert((!std::is_base_of<std::unary_function<C*, float>,
+ std::reference_wrapper<float(C::*)(int)> >::value), "");
+}
diff --git a/libcxx/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp
new file mode 100644
index 00000000000..609094dae40
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// reference_wrapper
+
+// has weak result type
+
+#include <functional>
+#include <type_traits>
+
+class functor1
+ : public std::unary_function<int, char>
+{
+};
+
+class functor2
+ : public std::binary_function<char, int, double>
+{
+};
+
+class functor3
+ : public std::unary_function<char, int>,
+ public std::binary_function<char, int, double>
+{
+public:
+ typedef float result_type;
+};
+
+class functor4
+ : public std::unary_function<char, int>,
+ public std::binary_function<char, int, double>
+{
+public:
+};
+
+class C {};
+
+template <class T>
+struct has_result_type
+{
+private:
+ struct two {char _; char __;};
+ template <class U> static two test(...);
+ template <class U> static char test(typename U::result_type* = 0);
+public:
+ static const bool value = sizeof(test<T>(0)) == 1;
+};
+
+int main()
+{
+ static_assert((std::is_same<std::reference_wrapper<functor1>::result_type,
+ char>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<functor2>::result_type,
+ double>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<functor3>::result_type,
+ float>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<void()>::result_type,
+ void>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type,
+ int*>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type,
+ void>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type,
+ int*>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type,
+ int*>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type,
+ int>::value), "");
+ static_assert((std::is_same<std::reference_wrapper<C()>::result_type,
+ C>::value), "");
+ static_assert(has_result_type<std::reference_wrapper<functor3> >::value, "");
+ static_assert(!has_result_type<std::reference_wrapper<functor4> >::value, "");
+ static_assert(!has_result_type<std::reference_wrapper<C> >::value, "");
+}
OpenPOWER on IntegriCloud