summaryrefslogtreecommitdiff
path: root/test/std/utilities/function.objects/arithmetic.operations
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
commit61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch)
treeec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/utilities/function.objects/arithmetic.operations
parentf857581820d15e410e9945d2fcd5f7163be25a96 (diff)
Notes
Diffstat (limited to 'test/std/utilities/function.objects/arithmetic.operations')
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp39
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp39
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp39
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp39
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp38
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp39
-rw-r--r--test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp61
7 files changed, 294 insertions, 0 deletions
diff --git a/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
new file mode 100644
index 0000000000000..490dc16b60e21
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// divides
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::divides<int> F;
+ const F f = F();
+ static_assert((std::is_same<int, F::first_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::second_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::result_type>::value), "" );
+ assert(f(36, 4) == 9);
+#if _LIBCPP_STD_VER > 11
+ typedef std::divides<> F2;
+ const F2 f2 = F2();
+ assert(f2(36, 4) == 9);
+ assert(f2(36.0, 4) == 9);
+ assert(f2(18, 4.0) == 4.5); // exact in binary
+
+ constexpr int foo = std::divides<int> () (3, 2);
+ static_assert ( foo == 1, "" );
+
+ constexpr int bar = std::divides<> () (3.0, 2);
+ static_assert ( bar == 1, "" );
+#endif
+}
diff --git a/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
new file mode 100644
index 0000000000000..9bda541f896a8
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// minus
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::minus<int> F;
+ const F f = F();
+ static_assert((std::is_same<int, F::first_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::second_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::result_type>::value), "" );
+ assert(f(3, 2) == 1);
+#if _LIBCPP_STD_VER > 11
+ typedef std::minus<> F2;
+ const F2 f2 = F2();
+ assert(f2(3,2) == 1);
+ assert(f2(3.0, 2) == 1);
+ assert(f2(3, 2.5) == 0.5);
+
+ constexpr int foo = std::minus<int> () (3, 2);
+ static_assert ( foo == 1, "" );
+
+ constexpr int bar = std::minus<> () (3.0, 2);
+ static_assert ( bar == 1, "" );
+#endif
+}
diff --git a/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp
new file mode 100644
index 0000000000000..ca5bba6d5b8ea
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// modulus
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::modulus<int> F;
+ const F f = F();
+ static_assert((std::is_same<int, F::first_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::second_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::result_type>::value), "" );
+ assert(f(36, 8) == 4);
+#if _LIBCPP_STD_VER > 11
+ typedef std::modulus<> F2;
+ const F2 f2 = F2();
+ assert(f2(36, 8) == 4);
+ assert(f2(36L, 8) == 4);
+ assert(f2(36, 8L) == 4);
+
+ constexpr int foo = std::modulus<int> () (3, 2);
+ static_assert ( foo == 1, "" );
+
+ constexpr int bar = std::modulus<> () (3L, 2);
+ static_assert ( bar == 1, "" );
+#endif
+}
diff --git a/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
new file mode 100644
index 0000000000000..f132c8d4bd9b2
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// multiplies
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::multiplies<int> F;
+ const F f = F();
+ static_assert((std::is_same<int, F::first_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::second_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::result_type>::value), "" );
+ assert(f(3, 2) == 6);
+#if _LIBCPP_STD_VER > 11
+ typedef std::multiplies<> F2;
+ const F2 f2 = F2();
+ assert(f2(3,2) == 6);
+ assert(f2(3.0, 2) == 6);
+ assert(f2(3, 2.5) == 7.5); // exact in binary
+
+ constexpr int foo = std::multiplies<int> () (3, 2);
+ static_assert ( foo == 6, "" );
+
+ constexpr int bar = std::multiplies<> () (3.0, 2);
+ static_assert ( bar == 6, "" );
+#endif
+}
diff --git a/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
new file mode 100644
index 0000000000000..0adac659123b4
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// negate
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::negate<int> F;
+ const F f = F();
+ static_assert((std::is_same<F::argument_type, int>::value), "" );
+ static_assert((std::is_same<F::result_type, int>::value), "" );
+ assert(f(36) == -36);
+#if _LIBCPP_STD_VER > 11
+ typedef std::negate<> F2;
+ const F2 f2 = F2();
+ assert(f2(36) == -36);
+ assert(f2(36L) == -36);
+ assert(f2(36.0) == -36);
+
+ constexpr int foo = std::negate<int> () (3);
+ static_assert ( foo == -3, "" );
+
+ constexpr int bar = std::negate<> () (3.0);
+ static_assert ( bar == -3, "" );
+#endif
+}
diff --git a/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
new file mode 100644
index 0000000000000..3c093fc093c32
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// plus
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::plus<int> F;
+ const F f = F();
+ static_assert((std::is_same<int, F::first_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::second_argument_type>::value), "" );
+ static_assert((std::is_same<int, F::result_type>::value), "" );
+ assert(f(3, 2) == 5);
+#if _LIBCPP_STD_VER > 11
+ typedef std::plus<> F2;
+ const F2 f2 = F2();
+ assert(f2(3,2) == 5);
+ assert(f2(3.0, 2) == 5);
+ assert(f2(3, 2.5) == 5.5);
+
+ constexpr int foo = std::plus<int> () (3, 2);
+ static_assert ( foo == 5, "" );
+
+ constexpr int bar = std::plus<> () (3.0, 2);
+ static_assert ( bar == 5, "" );
+#endif
+}
diff --git a/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp
new file mode 100644
index 0000000000000..72b4b4a0a1fe7
--- /dev/null
+++ b/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#include <functional>
+#include <string>
+
+template <class _Tp>
+struct is_transparent
+{
+private:
+ struct __two {char __lx; char __lxx;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::is_transparent* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+
+int main () {
+#if _LIBCPP_STD_VER > 11
+
+ static_assert ( !is_transparent<std::plus<int>>::value, "" );
+ static_assert ( !is_transparent<std::plus<std::string>>::value, "" );
+ static_assert ( is_transparent<std::plus<void>>::value, "" );
+ static_assert ( is_transparent<std::plus<>>::value, "" );
+
+ static_assert ( !is_transparent<std::minus<int>>::value, "" );
+ static_assert ( !is_transparent<std::minus<std::string>>::value, "" );
+ static_assert ( is_transparent<std::minus<void>>::value, "" );
+ static_assert ( is_transparent<std::minus<>>::value, "" );
+
+ static_assert ( !is_transparent<std::multiplies<int>>::value, "" );
+ static_assert ( !is_transparent<std::multiplies<std::string>>::value, "" );
+ static_assert ( is_transparent<std::multiplies<void>>::value, "" );
+ static_assert ( is_transparent<std::multiplies<>>::value, "" );
+
+ static_assert ( !is_transparent<std::divides<int>>::value, "" );
+ static_assert ( !is_transparent<std::divides<std::string>>::value, "" );
+ static_assert ( is_transparent<std::divides<void>>::value, "" );
+ static_assert ( is_transparent<std::divides<>>::value, "" );
+
+ static_assert ( !is_transparent<std::modulus<int>>::value, "" );
+ static_assert ( !is_transparent<std::modulus<std::string>>::value, "" );
+ static_assert ( is_transparent<std::modulus<void>>::value, "" );
+ static_assert ( is_transparent<std::modulus<>>::value, "" );
+
+ static_assert ( !is_transparent<std::negate<int>>::value, "" );
+ static_assert ( !is_transparent<std::negate<std::string>>::value, "" );
+ static_assert ( is_transparent<std::negate<void>>::value, "" );
+ static_assert ( is_transparent<std::negate<>>::value, "" );
+
+#endif
+
+ return 0;
+ }