diff --git a/include/type_traits b/include/type_traits index 576e28f2..8d55ea5e 100644 --- a/include/type_traits +++ b/include/type_traits @@ -205,145 +205,157 @@ namespace std template using void_t = void; // C++17 - // See C++14 20.10.4.1, primary type categories - template constexpr bool is_void_v - = is_void::value; // C++17 - template constexpr bool is_null_pointer_v - = is_null_pointer::value; // C++17 - template constexpr bool is_integral_v - = is_integral::value; // C++17 - template constexpr bool is_floating_point_v - = is_floating_point::value; // C++17 - template constexpr bool is_array_v - = is_array::value; // C++17 - template constexpr bool is_pointer_v - = is_pointer::value; // C++17 - template constexpr bool is_lvalue_reference_v - = is_lvalue_reference::value; // C++17 - template constexpr bool is_rvalue_reference_v - = is_rvalue_reference::value; // C++17 - template constexpr bool is_member_object_pointer_v - = is_member_object_pointer::value; // C++17 - template constexpr bool is_member_function_pointer_v - = is_member_function_pointer::value; // C++17 - template constexpr bool is_enum_v - = is_enum::value; // C++17 - template constexpr bool is_union_v - = is_union::value; // C++17 - template constexpr bool is_class_v - = is_class::value; // C++17 - template constexpr bool is_function_v - = is_function::value; // C++17 + // See C++14 20.10.4.1, primary type categories + template constexpr bool is_void_v + = is_void::value; // C++17 + template constexpr bool is_null_pointer_v + = is_null_pointer::value; // C++17 + template constexpr bool is_integral_v + = is_integral::value; // C++17 + template constexpr bool is_floating_point_v + = is_floating_point::value; // C++17 + template constexpr bool is_array_v + = is_array::value; // C++17 + template constexpr bool is_pointer_v + = is_pointer::value; // C++17 + template constexpr bool is_lvalue_reference_v + = is_lvalue_reference::value; // C++17 + template constexpr bool is_rvalue_reference_v + = is_rvalue_reference::value; // C++17 + template constexpr bool is_member_object_pointer_v + = is_member_object_pointer::value; // C++17 + template constexpr bool is_member_function_pointer_v + = is_member_function_pointer::value; // C++17 + template constexpr bool is_enum_v + = is_enum::value; // C++17 + template constexpr bool is_union_v + = is_union::value; // C++17 + template constexpr bool is_class_v + = is_class::value; // C++17 + template constexpr bool is_function_v + = is_function::value; // C++17 - // See C++14 20.10.4.2, composite type categories - template constexpr bool is_reference_v - = is_reference::value; // C++17 - template constexpr bool is_arithmetic_v - = is_arithmetic::value; // C++17 - template constexpr bool is_fundamental_v - = is_fundamental::value; // C++17 - template constexpr bool is_object_v - = is_object::value; // C++17 - template constexpr bool is_scalar_v - = is_scalar::value; // C++17 - template constexpr bool is_compound_v - = is_compound::value; // C++17 - template constexpr bool is_member_pointer_v - = is_member_pointer::value; // C++17 + // See C++14 20.10.4.2, composite type categories + template constexpr bool is_reference_v + = is_reference::value; // C++17 + template constexpr bool is_arithmetic_v + = is_arithmetic::value; // C++17 + template constexpr bool is_fundamental_v + = is_fundamental::value; // C++17 + template constexpr bool is_object_v + = is_object::value; // C++17 + template constexpr bool is_scalar_v + = is_scalar::value; // C++17 + template constexpr bool is_compound_v + = is_compound::value; // C++17 + template constexpr bool is_member_pointer_v + = is_member_pointer::value; // C++17 - // See C++14 20.10.4.3, type properties - template constexpr bool is_const_v - = is_const::value; // C++17 - template constexpr bool is_volatile_v - = is_volatile::value; // C++17 - template constexpr bool is_trivial_v - = is_trivial::value; // C++17 - template constexpr bool is_trivially_copyable_v - = is_trivially_copyable::value; // C++17 - template constexpr bool is_standard_layout_v - = is_standard_layout::value; // C++17 - template constexpr bool is_pod_v - = is_pod::value; // C++17 - template constexpr bool is_literal_type_v - = is_literal_type::value; // C++17 - template constexpr bool is_empty_v - = is_empty::value; // C++17 - template constexpr bool is_polymorphic_v - = is_polymorphic::value; // C++17 - template constexpr bool is_abstract_v - = is_abstract::value; // C++17 - template constexpr bool is_final_v - = is_final::value; // C++17 - template constexpr bool is_signed_v - = is_signed::value; // C++17 - template constexpr bool is_unsigned_v - = is_unsigned::value; // C++17 - template constexpr bool is_constructible_v - = is_constructible::value; // C++17 - template constexpr bool is_default_constructible_v - = is_default_constructible::value; // C++17 - template constexpr bool is_copy_constructible_v - = is_copy_constructible::value; // C++17 - template constexpr bool is_move_constructible_v - = is_move_constructible::value; // C++17 - template constexpr bool is_assignable_v - = is_assignable::value; // C++17 - template constexpr bool is_copy_assignable_v - = is_copy_assignable::value; // C++17 - template constexpr bool is_move_assignable_v - = is_move_assignable::value; // C++17 - template constexpr bool is_destructible_v - = is_destructible::value; // C++17 - template constexpr bool is_trivially_constructible_v - = is_trivially_constructible::value; // C++17 - template constexpr bool is_trivially_default_constructible_v - = is_trivially_default_constructible::value; // C++17 - template constexpr bool is_trivially_copy_constructible_v - = is_trivially_copy_constructible::value; // C++17 - template constexpr bool is_trivially_move_constructible_v - = is_trivially_move_constructible::value; // C++17 - template constexpr bool is_trivially_assignable_v - = is_trivially_assignable::value; // C++17 - template constexpr bool is_trivially_copy_assignable_v - = is_trivially_copy_assignable::value; // C++17 - template constexpr bool is_trivially_move_assignable_v - = is_trivially_move_assignable::value; // C++17 - template constexpr bool is_trivially_destructible_v - = is_trivially_destructible::value; // C++17 - template constexpr bool is_nothrow_constructible_v - = is_nothrow_constructible::value; // C++17 - template constexpr bool is_nothrow_default_constructible_v - = is_nothrow_default_constructible::value; // C++17 - template constexpr bool is_nothrow_copy_constructible_v - = is_nothrow_copy_constructible::value; // C++17 - template constexpr bool is_nothrow_move_constructible_v - = is_nothrow_move_constructible::value; // C++17 - template constexpr bool is_nothrow_assignable_v - = is_nothrow_assignable::value; // C++17 - template constexpr bool is_nothrow_copy_assignable_v - = is_nothrow_copy_assignable::value; // C++17 - template constexpr bool is_nothrow_move_assignable_v - = is_nothrow_move_assignable::value; // C++17 - template constexpr bool is_nothrow_destructible_v - = is_nothrow_destructible::value; // C++17 - template constexpr bool has_virtual_destructor_v - = has_virtual_destructor::value; // C++17 + // See C++14 20.10.4.3, type properties + template constexpr bool is_const_v + = is_const::value; // C++17 + template constexpr bool is_volatile_v + = is_volatile::value; // C++17 + template constexpr bool is_trivial_v + = is_trivial::value; // C++17 + template constexpr bool is_trivially_copyable_v + = is_trivially_copyable::value; // C++17 + template constexpr bool is_standard_layout_v + = is_standard_layout::value; // C++17 + template constexpr bool is_pod_v + = is_pod::value; // C++17 + template constexpr bool is_literal_type_v + = is_literal_type::value; // C++17 + template constexpr bool is_empty_v + = is_empty::value; // C++17 + template constexpr bool is_polymorphic_v + = is_polymorphic::value; // C++17 + template constexpr bool is_abstract_v + = is_abstract::value; // C++17 + template constexpr bool is_final_v + = is_final::value; // C++17 + template constexpr bool is_signed_v + = is_signed::value; // C++17 + template constexpr bool is_unsigned_v + = is_unsigned::value; // C++17 + template constexpr bool is_constructible_v + = is_constructible::value; // C++17 + template constexpr bool is_default_constructible_v + = is_default_constructible::value; // C++17 + template constexpr bool is_copy_constructible_v + = is_copy_constructible::value; // C++17 + template constexpr bool is_move_constructible_v + = is_move_constructible::value; // C++17 + template constexpr bool is_assignable_v + = is_assignable::value; // C++17 + template constexpr bool is_copy_assignable_v + = is_copy_assignable::value; // C++17 + template constexpr bool is_move_assignable_v + = is_move_assignable::value; // C++17 + template constexpr bool is_destructible_v + = is_destructible::value; // C++17 + template constexpr bool is_trivially_constructible_v + = is_trivially_constructible::value; // C++17 + template constexpr bool is_trivially_default_constructible_v + = is_trivially_default_constructible::value; // C++17 + template constexpr bool is_trivially_copy_constructible_v + = is_trivially_copy_constructible::value; // C++17 + template constexpr bool is_trivially_move_constructible_v + = is_trivially_move_constructible::value; // C++17 + template constexpr bool is_trivially_assignable_v + = is_trivially_assignable::value; // C++17 + template constexpr bool is_trivially_copy_assignable_v + = is_trivially_copy_assignable::value; // C++17 + template constexpr bool is_trivially_move_assignable_v + = is_trivially_move_assignable::value; // C++17 + template constexpr bool is_trivially_destructible_v + = is_trivially_destructible::value; // C++17 + template constexpr bool is_nothrow_constructible_v + = is_nothrow_constructible::value; // C++17 + template constexpr bool is_nothrow_default_constructible_v + = is_nothrow_default_constructible::value; // C++17 + template constexpr bool is_nothrow_copy_constructible_v + = is_nothrow_copy_constructible::value; // C++17 + template constexpr bool is_nothrow_move_constructible_v + = is_nothrow_move_constructible::value; // C++17 + template constexpr bool is_nothrow_assignable_v + = is_nothrow_assignable::value; // C++17 + template constexpr bool is_nothrow_copy_assignable_v + = is_nothrow_copy_assignable::value; // C++17 + template constexpr bool is_nothrow_move_assignable_v + = is_nothrow_move_assignable::value; // C++17 + template constexpr bool is_nothrow_destructible_v + = is_nothrow_destructible::value; // C++17 + template constexpr bool has_virtual_destructor_v + = has_virtual_destructor::value; // C++17 - // See C++14 20.10.5, type property queries - template constexpr size_t alignment_of_v - = alignment_of::value; // C++17 - template constexpr size_t rank_v - = rank::value; // C++17 - template constexpr size_t extent_v - = extent::value; // C++17 + // See C++14 20.10.5, type property queries + template constexpr size_t alignment_of_v + = alignment_of::value; // C++17 + template constexpr size_t rank_v + = rank::value; // C++17 + template constexpr size_t extent_v + = extent::value; // C++17 + + // See C++14 20.10.6, type relations + template constexpr bool is_same_v + = is_same::value; // C++17 + template constexpr bool is_base_of_v + = is_base_of::value; // C++17 + template constexpr bool is_convertible_v + = is_convertible::value; // C++17 + + // [meta.logical], logical operator traits: + template struct conjunction; // C++17 + template + constexpr bool conjunction_v = conjunction::value; // C++17 + template struct disjunction; // C++17 + template + constexpr bool disjunction_v = disjunction::value; // C++17 + template struct negation; // C++17 + template + constexpr bool negation_v = negation::value; // C++17 - // See C++14 20.10.6, type relations - template constexpr bool is_same_v - = is_same::value; // C++17 - template constexpr bool is_base_of_v - = is_base_of::value; // C++17 - template constexpr bool is_convertible_v - = is_convertible::value; // C++17 } */ @@ -409,9 +421,9 @@ _LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value; #if _LIBCPP_STD_VER > 14 template using bool_constant = integral_constant; -#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)> +#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)> #else -#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant +#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant #endif typedef _LIBCPP_BOOL_CONSTANT(true) true_type; @@ -462,6 +474,36 @@ struct __lazy_or : __lazy_or_impl<_P1::type::value, _Pr...> {}; template struct __lazy_not : integral_constant {}; +// __and_ +template struct __and_; +template<> struct __and_<> : true_type {}; + +template struct __and_<_B0> : _B0 {}; + +template +struct __and_<_B0, _B1> : conditional<_B0::value, _B1, _B0>::type {}; + +template +struct __and_<_B0, _B1, _B2, _Bn...> + : conditional<_B0::value, __and_<_B1, _B2, _Bn...>, _B0>::type {}; + +// __or_ +template struct __or_; +template<> struct __or_<> : false_type {}; + +template struct __or_<_B0> : _B0 {}; + +template +struct __or_<_B0, _B1> : conditional<_B0::value, _B0, _B1>::type {}; + +template +struct __or_<_B0, _B1, _B2, _Bn...> + : conditional<_B0::value, _B0, __or_<_B1, _B2, _Bn...> >::type {}; + +// __not_ +template +struct __not_ : conditional<_Tp::value, false_type, true_type>::type {}; + #endif // !defined(_LIBCPP_HAS_NO_VARIADICS) // is_const @@ -4257,7 +4299,21 @@ struct __has_operator_addressof #if _LIBCPP_STD_VER > 14 template using void_t = void; -#endif + +# ifndef _LIBCPP_HAS_NO_VARIADICS +template +struct conjunction : __and_<_Args...> {}; +template constexpr bool conjunction_v = conjunction<_Args...>::value; + +template +struct disjunction : __or_<_Args...> {}; +template constexpr bool disjunction_v = disjunction<_Args...>::value; + +template +struct negation : __not_<_Tp> {}; +template constexpr bool negation_v = negation<_Tp>::value; +# endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/test/std/utilities/meta/meta.logical/conjunction.pass.cpp b/test/std/utilities/meta/meta.logical/conjunction.pass.cpp new file mode 100644 index 00000000..dce58ec2 --- /dev/null +++ b/test/std/utilities/meta/meta.logical/conjunction.pass.cpp @@ -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 struct conjunction; // C++17 +// template +// constexpr bool conjunction_v = conjunction::value; // C++17 + +#include +#include + +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::value, "" ); + static_assert (!std::conjunction::value, "" ); + + static_assert ( std::conjunction_v<>, "" ); + static_assert ( std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + + static_assert ( std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + + static_assert ( std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + + static_assert ( std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + + static_assert ( std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); + + static_assert ( std::conjunction::value, "" ); + static_assert (!std::conjunction::value, "" ); + + static_assert ( std::conjunction_v, "" ); + static_assert (!std::conjunction_v, "" ); +} diff --git a/test/std/utilities/meta/meta.logical/disjunction.pass.cpp b/test/std/utilities/meta/meta.logical/disjunction.pass.cpp new file mode 100644 index 00000000..13cd9341 --- /dev/null +++ b/test/std/utilities/meta/meta.logical/disjunction.pass.cpp @@ -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 struct disjunction; // C++17 +// template +// constexpr bool disjunction_v = disjunction::value; // C++17 + +#include +#include + +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::value, "" ); + static_assert (!std::disjunction::value, "" ); + + static_assert (!std::disjunction_v<>, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert (!std::disjunction_v, "" ); + + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert (!std::disjunction::value, "" ); + + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert (!std::disjunction_v, "" ); + + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert ( std::disjunction::value, "" ); + static_assert (!std::disjunction::value, "" ); + + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert ( std::disjunction_v, "" ); + static_assert (!std::disjunction_v, "" ); + + static_assert ( std::disjunction::value, "" ); + static_assert (!std::disjunction::value, "" ); + + static_assert ( std::disjunction_v, "" ); + static_assert (!std::disjunction_v, "" ); +} diff --git a/test/std/utilities/meta/meta.logical/negation.pass.cpp b/test/std/utilities/meta/meta.logical/negation.pass.cpp new file mode 100644 index 00000000..76ff6c5b --- /dev/null +++ b/test/std/utilities/meta/meta.logical/negation.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// type_traits + +// template struct negation; // C++17 +// template +// constexpr bool negation_v = negation::value; // C++17 + +#include +#include + +struct True { static constexpr bool value = true; }; +struct False { static constexpr bool value = false; }; + +int main() +{ + static_assert (!std::negation::value, "" ); + static_assert ( std::negation::value, "" ); + + static_assert (!std::negation_v, "" ); + static_assert ( std::negation_v, "" ); + + static_assert (!std::negation::value, "" ); + static_assert ( std::negation::value, "" ); + + static_assert (!std::negation_v, "" ); + static_assert ( std::negation_v, "" ); + + static_assert ( std::negation>::value, "" ); + static_assert (!std::negation>::value, "" ); +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 926aca76..7d8238f3 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -76,7 +76,7 @@ P0007R1LWGConstant View: A proposal for a std::as_const helper function template.KonaIn progress P0156R0LWGVariadic lock_guard(rev 3).Kona P0074R0LWGMaking std::owner_less more flexibleKonaComplete3.8 - P0013R1LWGLogical type traits rev 2KonaIn progress + P0013R1LWGLogical type traits rev 2KonaComplete3.8