diff options
Diffstat (limited to 'libcxx/test/std/utilities/function.objects/comparisons')
7 files changed, 313 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/function.objects/comparisons/equal_to.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/equal_to.pass.cpp new file mode 100644 index 00000000000..3d1c0b5cecd --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/equal_to.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> + +// equal_to + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::equal_to<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(!f(36, 6)); +#if _LIBCPP_STD_VER > 11 + typedef std::equal_to<> F2; + const F2 f2 = F2(); + assert(f2(36, 36)); + assert(!f2(36, 6)); + assert(f2(36, 36.0)); + assert(f2(36.0, 36L)); + + constexpr bool foo = std::equal_to<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::equal_to<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/comparisons/greater.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/greater.pass.cpp new file mode 100644 index 00000000000..5a88f4362dc --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/greater.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> + +// greater + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::greater<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert(f(36, 6)); + assert(!f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::greater<> F2; + const F2 f2 = F2(); + assert(!f2(36, 36)); + assert(f2(36, 6)); + assert(!f2(6, 36)); + assert( f2(36, 6.0)); + assert( f2(36.0, 6)); + assert(!f2(6, 36.0)); + assert(!f2(6.0, 36)); + + constexpr bool foo = std::greater<int> () (36, 36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::greater<> () (36.0, 36); + static_assert ( !bar, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/comparisons/greater_equal.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/greater_equal.pass.cpp new file mode 100644 index 00000000000..22444c79420 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/greater_equal.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> + +// greater_equal + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::greater_equal<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(f(36, 6)); + assert(!f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::greater_equal<> F2; + const F2 f2 = F2(); + assert(f2(36, 36)); + assert(f2(36, 6)); + assert(!f2(6, 36)); + assert( f2(36, 6.0)); + assert( f2(36.0, 6)); + assert(!f2(6, 36.0)); + assert(!f2(6.0, 36)); + + constexpr bool foo = std::greater_equal<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::greater_equal<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/comparisons/less.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/less.pass.cpp new file mode 100644 index 00000000000..99cdd1291bb --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/less.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> + +// less + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::less<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert(!f(36, 6)); + assert(f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::less<> F2; + const F2 f2 = F2(); + assert(!f2(36, 36)); + assert(!f2(36, 6)); + assert( f2(6, 36)); + assert(!f2(36, 6.0)); + assert(!f2(36.0, 6)); + assert( f2(6, 36.0)); + assert( f2(6.0, 36)); + + constexpr bool foo = std::less<int> () (36, 36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::less<> () (36.0, 36); + static_assert ( !bar, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/comparisons/less_equal.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/less_equal.pass.cpp new file mode 100644 index 00000000000..116906eaafe --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/less_equal.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> + +// less_equal + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::less_equal<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(f(36, 36)); + assert(!f(36, 6)); + assert(f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::less_equal<> F2; + const F2 f2 = F2(); + assert( f2(36, 36)); + assert(!f2(36, 6)); + assert( f2(6, 36)); + assert(!f2(36, 6.0)); + assert(!f2(36.0, 6)); + assert( f2(6, 36.0)); + assert( f2(6.0, 36)); + + constexpr bool foo = std::less_equal<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::less_equal<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/comparisons/not_equal_to.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/not_equal_to.pass.cpp new file mode 100644 index 00000000000..4b61bf8b838 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/not_equal_to.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// not_equal_to + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::not_equal_to<int> F; + const F f = F(); + static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), ""); + assert(!f(36, 36)); + assert(f(36, 6)); +#if _LIBCPP_STD_VER > 11 + typedef std::not_equal_to<> F2; + const F2 f2 = F2(); + assert(!f2(36, 36)); + assert( f2(36, 6)); + assert( f2(36, 6.0)); + assert( f2(36.0, 6)); + assert(!f2(36.0, 36)); + assert(!f2(36, 36.0)); + + constexpr bool foo = std::not_equal_to<int> () (36, 36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::not_equal_to<> () (36.0, 36); + static_assert ( !bar, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/comparisons/transparent.pass.cpp b/libcxx/test/std/utilities/function.objects/comparisons/transparent.pass.cpp new file mode 100644 index 00000000000..41ce4bcae65 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/comparisons/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::less<int>>::value, "" ); + static_assert ( !is_transparent<std::less<std::string>>::value, "" ); + static_assert ( is_transparent<std::less<void>>::value, "" ); + static_assert ( is_transparent<std::less<>>::value, "" ); + + static_assert ( !is_transparent<std::less_equal<int>>::value, "" ); + static_assert ( !is_transparent<std::less_equal<std::string>>::value, "" ); + static_assert ( is_transparent<std::less_equal<void>>::value, "" ); + static_assert ( is_transparent<std::less_equal<>>::value, "" ); + + static_assert ( !is_transparent<std::equal_to<int>>::value, "" ); + static_assert ( !is_transparent<std::equal_to<std::string>>::value, "" ); + static_assert ( is_transparent<std::equal_to<void>>::value, "" ); + static_assert ( is_transparent<std::equal_to<>>::value, "" ); + + static_assert ( !is_transparent<std::not_equal_to<int>>::value, "" ); + static_assert ( !is_transparent<std::not_equal_to<std::string>>::value, "" ); + static_assert ( is_transparent<std::not_equal_to<void>>::value, "" ); + static_assert ( is_transparent<std::not_equal_to<>>::value, "" ); + + static_assert ( !is_transparent<std::greater<int>>::value, "" ); + static_assert ( !is_transparent<std::greater<std::string>>::value, "" ); + static_assert ( is_transparent<std::greater<void>>::value, "" ); + static_assert ( is_transparent<std::greater<>>::value, "" ); + + static_assert ( !is_transparent<std::greater_equal<int>>::value, "" ); + static_assert ( !is_transparent<std::greater_equal<std::string>>::value, "" ); + static_assert ( is_transparent<std::greater_equal<void>>::value, "" ); + static_assert ( is_transparent<std::greater_equal<>>::value, "" ); + +#endif + + return 0; + } |