summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities/function.objects/arithmetic.operations
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-12-20 01:40:03 +0000
committerEric Fiselier <eric@efcs.ca>2014-12-20 01:40:03 +0000
commit5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch)
treeafde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/std/utilities/function.objects/arithmetic.operations
parentf11e8eab527fba316c64112f6e05de1a79693a3e (diff)
downloadbcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz
bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/std/utilities/function.objects/arithmetic.operations')
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp37
-rw-r--r--libcxx/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp61
7 files changed, 283 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
new file mode 100644
index 00000000000..74298f23b7c
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/arithmetic.operations/divides.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>
+
+// divides
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::divides<int> F;
+ const F f = F();
+ static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::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/libcxx/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
new file mode 100644
index 00000000000..9a496a8066c
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/arithmetic.operations/minus.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>
+
+// minus
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::minus<int> F;
+ const F f = F();
+ static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::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/libcxx/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp
new file mode 100644
index 00000000000..3c178819231
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/arithmetic.operations/modulus.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>
+
+// modulus
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::modulus<int> F;
+ const F f = F();
+ static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::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/libcxx/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
new file mode 100644
index 00000000000..97287e6c8da
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/arithmetic.operations/multiplies.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>
+
+// multiplies
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::multiplies<int> F;
+ const F f = F();
+ static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::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/libcxx/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
new file mode 100644
index 00000000000..3ffb7051bfd
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/arithmetic.operations/negate.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>
+
+// negate
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::negate<int> F;
+ const F f = F();
+ static_assert((std::is_base_of<std::unary_function<int, int>, F>::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/libcxx/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
new file mode 100644
index 00000000000..44001a0e5f4
--- /dev/null
+++ b/libcxx/test/std/utilities/function.objects/arithmetic.operations/plus.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>
+
+// plus
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ typedef std::plus<int> F;
+ const F f = F();
+ static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::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/libcxx/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp b/libcxx/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp
new file mode 100644
index 00000000000..72b4b4a0a1f
--- /dev/null
+++ b/libcxx/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;
+ }
OpenPOWER on IntegriCloud