Implement P0013R1: Logical Operator Type Traits. Make a hidden implementation (__and_, __or_, and __not_) so that we can use them elsewhere in non-C++17 code - for example, in the LFTS
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@253215 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -344,6 +344,18 @@ namespace std
|
|||||||
= is_base_of<Base, Derived>::value; // C++17
|
= is_base_of<Base, Derived>::value; // C++17
|
||||||
template <class From, class To> constexpr bool is_convertible_v
|
template <class From, class To> constexpr bool is_convertible_v
|
||||||
= is_convertible<From, To>::value; // C++17
|
= is_convertible<From, To>::value; // C++17
|
||||||
|
|
||||||
|
// [meta.logical], logical operator traits:
|
||||||
|
template<class... B> struct conjunction; // C++17
|
||||||
|
template<class... B>
|
||||||
|
constexpr bool conjunction_v = conjunction<B...>::value; // C++17
|
||||||
|
template<class... B> struct disjunction; // C++17
|
||||||
|
template<class... B>
|
||||||
|
constexpr bool disjunction_v = disjunction<B...>::value; // C++17
|
||||||
|
template<class B> struct negation; // C++17
|
||||||
|
template<class B>
|
||||||
|
constexpr bool negation_v = negation<B>::value; // C++17
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@@ -462,6 +474,36 @@ struct __lazy_or : __lazy_or_impl<_P1::type::value, _Pr...> {};
|
|||||||
template <class _Pred>
|
template <class _Pred>
|
||||||
struct __lazy_not : integral_constant<bool, !_Pred::type::value> {};
|
struct __lazy_not : integral_constant<bool, !_Pred::type::value> {};
|
||||||
|
|
||||||
|
// __and_
|
||||||
|
template<class...> struct __and_;
|
||||||
|
template<> struct __and_<> : true_type {};
|
||||||
|
|
||||||
|
template<class _B0> struct __and_<_B0> : _B0 {};
|
||||||
|
|
||||||
|
template<class _B0, class _B1>
|
||||||
|
struct __and_<_B0, _B1> : conditional<_B0::value, _B1, _B0>::type {};
|
||||||
|
|
||||||
|
template<class _B0, class _B1, class _B2, class... _Bn>
|
||||||
|
struct __and_<_B0, _B1, _B2, _Bn...>
|
||||||
|
: conditional<_B0::value, __and_<_B1, _B2, _Bn...>, _B0>::type {};
|
||||||
|
|
||||||
|
// __or_
|
||||||
|
template<class...> struct __or_;
|
||||||
|
template<> struct __or_<> : false_type {};
|
||||||
|
|
||||||
|
template<class _B0> struct __or_<_B0> : _B0 {};
|
||||||
|
|
||||||
|
template<class _B0, class _B1>
|
||||||
|
struct __or_<_B0, _B1> : conditional<_B0::value, _B0, _B1>::type {};
|
||||||
|
|
||||||
|
template<class _B0, class _B1, class _B2, class... _Bn>
|
||||||
|
struct __or_<_B0, _B1, _B2, _Bn...>
|
||||||
|
: conditional<_B0::value, _B0, __or_<_B1, _B2, _Bn...> >::type {};
|
||||||
|
|
||||||
|
// __not_
|
||||||
|
template<class _Tp>
|
||||||
|
struct __not_ : conditional<_Tp::value, false_type, true_type>::type {};
|
||||||
|
|
||||||
#endif // !defined(_LIBCPP_HAS_NO_VARIADICS)
|
#endif // !defined(_LIBCPP_HAS_NO_VARIADICS)
|
||||||
|
|
||||||
// is_const
|
// is_const
|
||||||
@@ -4257,7 +4299,21 @@ struct __has_operator_addressof
|
|||||||
|
|
||||||
#if _LIBCPP_STD_VER > 14
|
#if _LIBCPP_STD_VER > 14
|
||||||
template <class...> using void_t = void;
|
template <class...> using void_t = void;
|
||||||
#endif
|
|
||||||
|
# ifndef _LIBCPP_HAS_NO_VARIADICS
|
||||||
|
template <class... _Args>
|
||||||
|
struct conjunction : __and_<_Args...> {};
|
||||||
|
template<class... _Args> constexpr bool conjunction_v = conjunction<_Args...>::value;
|
||||||
|
|
||||||
|
template <class... _Args>
|
||||||
|
struct disjunction : __or_<_Args...> {};
|
||||||
|
template<class... _Args> constexpr bool disjunction_v = disjunction<_Args...>::value;
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
struct negation : __not_<_Tp> {};
|
||||||
|
template<class _Tp> constexpr bool negation_v = negation<_Tp>::value;
|
||||||
|
# endif // _LIBCPP_HAS_NO_VARIADICS
|
||||||
|
#endif // _LIBCPP_STD_VER > 14
|
||||||
|
|
||||||
_LIBCPP_END_NAMESPACE_STD
|
_LIBCPP_END_NAMESPACE_STD
|
||||||
|
|
||||||
|
66
test/std/utilities/meta/meta.logical/conjunction.pass.cpp
Normal file
66
test/std/utilities/meta/meta.logical/conjunction.pass.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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, c++14
|
||||||
|
// type_traits
|
||||||
|
|
||||||
|
// template<class... B> struct conjunction; // C++17
|
||||||
|
// template<class... B>
|
||||||
|
// constexpr bool conjunction_v = conjunction<B...>::value; // C++17
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
struct True { static constexpr bool value = true; };
|
||||||
|
struct False { static constexpr bool value = false; };
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
static_assert ( std::conjunction<>::value, "" );
|
||||||
|
static_assert ( std::conjunction<std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction_v<>, "" );
|
||||||
|
static_assert ( std::conjunction_v<std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction<std::true_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::true_type, std::false_type>::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type, std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction_v<std::true_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::true_type, std::false_type>, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type, std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction<std::true_type, std::true_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::true_type, std::false_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type, std::true_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type, std::false_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::true_type, std::true_type, std::false_type>::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::true_type, std::false_type, std::false_type>::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type, std::true_type, std::false_type>::value, "" );
|
||||||
|
static_assert (!std::conjunction<std::false_type, std::false_type, std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction_v<std::true_type, std::true_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::true_type, std::false_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type, std::true_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type, std::false_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::true_type, std::true_type, std::false_type>, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::true_type, std::false_type, std::false_type>, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type, std::true_type, std::false_type>, "" );
|
||||||
|
static_assert (!std::conjunction_v<std::false_type, std::false_type, std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction<True >::value, "" );
|
||||||
|
static_assert (!std::conjunction<False>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::conjunction_v<True >, "" );
|
||||||
|
static_assert (!std::conjunction_v<False>, "" );
|
||||||
|
}
|
66
test/std/utilities/meta/meta.logical/disjunction.pass.cpp
Normal file
66
test/std/utilities/meta/meta.logical/disjunction.pass.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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, c++14
|
||||||
|
// type_traits
|
||||||
|
|
||||||
|
// template<class... B> struct disjunction; // C++17
|
||||||
|
// template<class... B>
|
||||||
|
// constexpr bool disjunction_v = disjunction<B...>::value; // C++17
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
struct True { static constexpr bool value = true; };
|
||||||
|
struct False { static constexpr bool value = false; };
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
static_assert (!std::disjunction<>::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::true_type >::value, "" );
|
||||||
|
static_assert (!std::disjunction<std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert (!std::disjunction_v<>, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::true_type >, "" );
|
||||||
|
static_assert (!std::disjunction_v<std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::disjunction<std::true_type, std::true_type >::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::true_type, std::false_type>::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::false_type, std::true_type >::value, "" );
|
||||||
|
static_assert (!std::disjunction<std::false_type, std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::disjunction_v<std::true_type, std::true_type >, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::true_type, std::false_type>, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::false_type, std::true_type >, "" );
|
||||||
|
static_assert (!std::disjunction_v<std::false_type, std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::disjunction<std::true_type, std::true_type, std::true_type >::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::true_type, std::false_type, std::true_type >::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::false_type, std::true_type, std::true_type >::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::false_type, std::false_type, std::true_type >::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::true_type, std::true_type, std::false_type>::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::true_type, std::false_type, std::false_type>::value, "" );
|
||||||
|
static_assert ( std::disjunction<std::false_type, std::true_type, std::false_type>::value, "" );
|
||||||
|
static_assert (!std::disjunction<std::false_type, std::false_type, std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::disjunction_v<std::true_type, std::true_type, std::true_type >, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::true_type, std::false_type, std::true_type >, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::false_type, std::true_type, std::true_type >, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::false_type, std::false_type, std::true_type >, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::true_type, std::true_type, std::false_type>, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::true_type, std::false_type, std::false_type>, "" );
|
||||||
|
static_assert ( std::disjunction_v<std::false_type, std::true_type, std::false_type>, "" );
|
||||||
|
static_assert (!std::disjunction_v<std::false_type, std::false_type, std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::disjunction<True >::value, "" );
|
||||||
|
static_assert (!std::disjunction<False>::value, "" );
|
||||||
|
|
||||||
|
static_assert ( std::disjunction_v<True >, "" );
|
||||||
|
static_assert (!std::disjunction_v<False>, "" );
|
||||||
|
}
|
39
test/std/utilities/meta/meta.logical/negation.pass.cpp
Normal file
39
test/std/utilities/meta/meta.logical/negation.pass.cpp
Normal file
@@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||||
|
// type_traits
|
||||||
|
|
||||||
|
// template<class B> struct negation; // C++17
|
||||||
|
// template<class B>
|
||||||
|
// constexpr bool negation_v = negation<B>::value; // C++17
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
struct True { static constexpr bool value = true; };
|
||||||
|
struct False { static constexpr bool value = false; };
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
static_assert (!std::negation<std::true_type >::value, "" );
|
||||||
|
static_assert ( std::negation<std::false_type>::value, "" );
|
||||||
|
|
||||||
|
static_assert (!std::negation_v<std::true_type >, "" );
|
||||||
|
static_assert ( std::negation_v<std::false_type>, "" );
|
||||||
|
|
||||||
|
static_assert (!std::negation<True >::value, "" );
|
||||||
|
static_assert ( std::negation<False>::value, "" );
|
||||||
|
|
||||||
|
static_assert (!std::negation_v<True >, "" );
|
||||||
|
static_assert ( std::negation_v<False>, "" );
|
||||||
|
|
||||||
|
static_assert ( std::negation<std::negation<std::true_type >>::value, "" );
|
||||||
|
static_assert (!std::negation<std::negation<std::false_type>>::value, "" );
|
||||||
|
}
|
@@ -76,7 +76,7 @@
|
|||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0007R1.html">P0007R1</a></td><td>LWG</td><td>Constant View: A proposal for a <tt>std::as_const</tt> helper function template.</td><td>Kona</td><td>In progress</td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0007R1.html">P0007R1</a></td><td>LWG</td><td>Constant View: A proposal for a <tt>std::as_const</tt> helper function template.</td><td>Kona</td><td>In progress</td><td></td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0156R0.htm" >P0156R0</a></td><td>LWG</td><td>Variadic lock_guard(rev 3).</td><td>Kona</td><td></td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0156R0.htm" >P0156R0</a></td><td>LWG</td><td>Variadic lock_guard(rev 3).</td><td>Kona</td><td></td><td></td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0074R0.html">P0074R0</a></td><td>LWG</td><td>Making <tt>std::owner_less</tt> more flexible</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0074R0.html">P0074R0</a></td><td>LWG</td><td>Making <tt>std::owner_less</tt> more flexible</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0013R1.html">P0013R1</a></td><td>LWG</td><td>Logical type traits rev 2</td><td>Kona</td><td>In progress</td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0013R1.html">P0013R1</a></td><td>LWG</td><td>Logical type traits rev 2</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
|
||||||
<!-- <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->
|
<!-- <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user