From 13320a50e5be876b2c2991cbca8a6ed37fce56fd Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 26 Nov 2016 18:45:03 +0000 Subject: Implement conjuntion/disjuntion/negation for LFTS v2. Same code and tests for the ones in std:: llvm-svn: 287988 --- libcxx/include/experimental/type_traits | 18 ++++++ .../meta/meta.logical/conjunction.pass.cpp | 68 ++++++++++++++++++++++ .../meta/meta.logical/disjunction.pass.cpp | 68 ++++++++++++++++++++++ .../utilities/meta/meta.logical/negation.pass.cpp | 41 +++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 libcxx/test/std/experimental/utilities/meta/meta.logical/conjunction.pass.cpp create mode 100644 libcxx/test/std/experimental/utilities/meta/meta.logical/disjunction.pass.cpp create mode 100644 libcxx/test/std/experimental/utilities/meta/meta.logical/negation.pass.cpp diff --git a/libcxx/include/experimental/type_traits b/libcxx/include/experimental/type_traits index 524d9800b05..d6901d41a61 100644 --- a/libcxx/include/experimental/type_traits +++ b/libcxx/include/experimental/type_traits @@ -459,6 +459,24 @@ template using raw_invocation_type_t = typename raw_invocation_type<_Tp>::type; */ +// 3.3.3, Logical operator traits +template using void_t = void; + +template +struct conjunction : _VSTD::__and_<_Args...> {}; +template +_LIBCPP_CONSTEXPR bool conjunction_v = conjunction<_Args...>::value; + +template +struct disjunction : _VSTD::__or_<_Args...> {}; +template +_LIBCPP_CONSTEXPR bool disjunction_v = disjunction<_Args...>::value; + +template +struct negation : _VSTD::__not_<_Tp> {}; +template +_LIBCPP_CONSTEXPR bool negation_v = negation<_Tp>::value; + // 3.3.4, Detection idiom template using void_t = void; diff --git a/libcxx/test/std/experimental/utilities/meta/meta.logical/conjunction.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.logical/conjunction.pass.cpp new file mode 100644 index 00000000000..cb8db1febd2 --- /dev/null +++ b/libcxx/test/std/experimental/utilities/meta/meta.logical/conjunction.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// + +// template struct conjunction; // C++17 +// template +// constexpr bool conjunction_v = conjunction::value; // C++17 + +#include +#include + +namespace ex = std::experimental; + +struct True { static constexpr bool value = true; }; +struct False { static constexpr bool value = false; }; + +int main() +{ + static_assert ( ex::conjunction<>::value, "" ); + static_assert ( ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + + static_assert ( ex::conjunction_v<>, "" ); + static_assert ( ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + + static_assert ( ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + + static_assert ( ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + + static_assert ( ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + + static_assert ( ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); + + static_assert ( ex::conjunction::value, "" ); + static_assert (!ex::conjunction::value, "" ); + + static_assert ( ex::conjunction_v, "" ); + static_assert (!ex::conjunction_v, "" ); +} diff --git a/libcxx/test/std/experimental/utilities/meta/meta.logical/disjunction.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.logical/disjunction.pass.cpp new file mode 100644 index 00000000000..dcdbf09fb09 --- /dev/null +++ b/libcxx/test/std/experimental/utilities/meta/meta.logical/disjunction.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// + +// template struct disjunction; +// template +// constexpr bool disjunction_v = disjunction::value; + +#include +#include + +namespace ex = std::experimental; + +struct True { static constexpr bool value = true; }; +struct False { static constexpr bool value = false; }; + +int main() +{ + static_assert (!ex::disjunction<>::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert (!ex::disjunction::value, "" ); + + static_assert (!ex::disjunction_v<>, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert (!ex::disjunction_v, "" ); + + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert (!ex::disjunction::value, "" ); + + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert (!ex::disjunction_v, "" ); + + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert ( ex::disjunction::value, "" ); + static_assert (!ex::disjunction::value, "" ); + + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert ( ex::disjunction_v, "" ); + static_assert (!ex::disjunction_v, "" ); + + static_assert ( ex::disjunction::value, "" ); + static_assert (!ex::disjunction::value, "" ); + + static_assert ( ex::disjunction_v, "" ); + static_assert (!ex::disjunction_v, "" ); +} diff --git a/libcxx/test/std/experimental/utilities/meta/meta.logical/negation.pass.cpp b/libcxx/test/std/experimental/utilities/meta/meta.logical/negation.pass.cpp new file mode 100644 index 00000000000..b0d43d7e512 --- /dev/null +++ b/libcxx/test/std/experimental/utilities/meta/meta.logical/negation.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// + +// template struct negation; +// template +// constexpr bool negation_v = negation::value; + +#include +#include + +namespace ex = std::experimental; + +struct True { static constexpr bool value = true; }; +struct False { static constexpr bool value = false; }; + +int main() +{ + static_assert (!ex::negation::value, "" ); + static_assert ( ex::negation::value, "" ); + + static_assert (!ex::negation_v, "" ); + static_assert ( ex::negation_v, "" ); + + static_assert (!ex::negation::value, "" ); + static_assert ( ex::negation::value, "" ); + + static_assert (!ex::negation_v, "" ); + static_assert ( ex::negation_v, "" ); + + static_assert ( ex::negation>::value, "" ); + static_assert (!ex::negation>::value, "" ); +} -- cgit v1.2.3