From: Ville Voutilainen Date: Fri, 17 Oct 2014 12:21:21 +0000 (+0300) Subject: Implement the Library Fundamentals v1 variable templates. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=37285913f31c9877d93c440cdf8c8be4d73c3a02;p=gcc.git Implement the Library Fundamentals v1 variable templates. 2014-10-17 Ville Voutilainen Implement the Library Fundamentals v1 variable templates. * include/Makefile.am: Add the new header. * include/Makefile.in: Regenerate. * include/experimental/type_traits: New. * testsuite/experimental/type_traits/value.cc: Likewise. From-SVN: r216397 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 97508418beb..b915a0b85b1 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2014-10-17 Ville Voutilainen + + Implement the Library Fundamentals v1 variable templates. + * include/Makefile.am: Add the new header. + * include/Makefile.in: Regenerate. + * include/experimental/type_traits: New. + * testsuite/experimental/type_traits/value.cc: Likewise. + 2014-10-16 Paolo Carlini * testsuite/lib/libstdc++.exp: Prefer -std=gnu++11. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index e3aed848615..1ee8ddcb38d 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -643,7 +643,8 @@ experimental_headers = \ ${experimental_srcdir}/optional \ ${experimental_srcdir}/string_view \ ${experimental_srcdir}/string_view.tcc \ - ${experimental_srcdir}/tuple + ${experimental_srcdir}/tuple \ + ${experimental_srcdir}/type_traits # This is the common subset of C++ files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index b49c501a6f3..a2262e898c4 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -909,7 +909,8 @@ experimental_headers = \ ${experimental_srcdir}/optional \ ${experimental_srcdir}/string_view \ ${experimental_srcdir}/string_view.tcc \ - ${experimental_srcdir}/tuple + ${experimental_srcdir}/tuple \ + ${experimental_srcdir}/type_traits # This is the common subset of C++ files that all three "C" header models use. diff --git a/libstdc++-v3/include/experimental/type_traits b/libstdc++-v3/include/experimental/type_traits new file mode 100644 index 00000000000..93dd8ce3945 --- /dev/null +++ b/libstdc++-v3/include/experimental/type_traits @@ -0,0 +1,226 @@ +// Variable Templates For Type Traits -*- C++ -*- + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file experimental/type_traits + * This is a TS C++ Library header. + */ + +// +// N3932 Variable Templates For Type Traits (Revision 1) +// + +#ifndef _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS +#define _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS 1 + +#pragma GCC system_header + +#if __cplusplus <= 201103L +# include +#else + +#include + + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace experimental +{ +inline namespace fundamentals_v1 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +// See C++14 §20.10.4.1, primary type categories +template + constexpr bool is_void_v = is_void<_Tp>::value; +template + constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value; +template + constexpr bool is_integral_v = is_integral<_Tp>::value; +template + constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +template + constexpr bool is_array_v = is_array<_Tp>::value; +template + constexpr bool is_pointer_v = is_pointer<_Tp>::value; +template + constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value; +template + constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value; +template + constexpr bool is_member_object_pointer_v = + is_member_object_pointer<_Tp>::value; +template + constexpr bool is_member_function_pointer_v = + is_member_function_pointer<_Tp>::value; +template + constexpr bool is_enum_v = is_enum<_Tp>::value; +template + constexpr bool is_union_v = is_union<_Tp>::value; +template + constexpr bool is_class_v = is_class<_Tp>::value; +template + constexpr bool is_function_v = is_function<_Tp>::value; + +// See C++14 §20.10.4.2, composite type categories +template + constexpr bool is_reference_v = is_reference<_Tp>::value; +template + constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; +template + constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; +template + constexpr bool is_object_v = is_object<_Tp>::value; +template + constexpr bool is_scalar_v = is_scalar<_Tp>::value; +template + constexpr bool is_compound_v = is_compound<_Tp>::value; +template + constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; + +// See C++14 §20.10.4.3, type properties +template + constexpr bool is_const_v = is_const<_Tp>::value; +template + constexpr bool is_volatile_v = is_volatile<_Tp>::value; +template + constexpr bool is_trivial_v = is_trivial<_Tp>::value; +template + constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value; +template + constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value; +template + constexpr bool is_pod_v = is_pod<_Tp>::value; +template + constexpr bool is_literal_type_v = is_literal_type<_Tp>::value; +template + constexpr bool is_empty_v = is_empty<_Tp>::value; +template + constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value; +template + constexpr bool is_abstract_v = is_abstract<_Tp>::value; +template + constexpr bool is_final_v = is_final<_Tp>::value; +template + constexpr bool is_signed_v = is_signed<_Tp>::value; +template + constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; +template + constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value; +template + constexpr bool is_default_constructible_v = + is_default_constructible<_Tp>::value; +template + constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value; +template + constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value; +template + constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value; +template + constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value; +template + constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value; +template + constexpr bool is_destructible_v = is_destructible<_Tp>::value; +template + constexpr bool is_trivially_constructible_v = + is_trivially_constructible<_Tp, _Args...>::value; +template + constexpr bool is_trivially_default_constructible_v = + is_trivially_default_constructible<_Tp>::value; +template + constexpr bool is_trivially_copy_constructible_v = + is_trivially_copy_constructible<_Tp>::value; +template + constexpr bool is_trivially_move_constructible_v = + is_trivially_move_constructible<_Tp>::value; +template + constexpr bool is_trivially_assignable_v = + is_trivially_assignable<_Tp, _Up>::value; +template + constexpr bool is_trivially_copy_assignable_v = + is_trivially_copy_assignable<_Tp>::value; +template + constexpr bool is_trivially_move_assignable_v = + is_trivially_move_assignable<_Tp>::value; +template + constexpr bool is_trivially_destructible_v = + is_trivially_destructible<_Tp>::value; +template + constexpr bool is_nothrow_constructible_v = + is_nothrow_constructible<_Tp, _Args...>::value; +template + constexpr bool is_nothrow_default_constructible_v = + is_nothrow_default_constructible<_Tp>::value; +template + constexpr bool is_nothrow_copy_constructible_v = + is_nothrow_copy_constructible<_Tp>::value; +template + constexpr bool is_nothrow_move_constructible_v = + is_nothrow_move_constructible<_Tp>::value; +template + constexpr bool is_nothrow_assignable_v = + is_nothrow_assignable<_Tp, _Up>::value; +template + constexpr bool is_nothrow_copy_assignable_v = + is_nothrow_copy_assignable<_Tp>::value; +template + constexpr bool is_nothrow_move_assignable_v = + is_nothrow_move_assignable<_Tp>::value; +template + constexpr bool is_nothrow_destructible_v = + is_nothrow_destructible<_Tp>::value; +template + constexpr bool has_virtual_destructor_v = + has_virtual_destructor<_Tp>::value; + +// See C++14 §20.10.5, type property queries +template + constexpr size_t alignment_of_v = alignment_of<_Tp>::value; +template + constexpr size_t rank_v = rank<_Tp>::value; +template + constexpr size_t extent_v = extent<_Tp, _Idx>::value; + +// See C++14 §20.10.6, type relations +template + constexpr bool is_same_v = is_same<_Tp, _Up>::value; +template + constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value; +template + constexpr bool is_convertible_v = is_convertible<_From, _To>::value; + + + // 3.3.2, Other type transformations + // invocation_type (still unimplemented) + // raw_invocation_type (still unimplemented) + // invocation_type_t (still unimplemented) + // raw_invocation_type_t (still unimplemented) +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + +#endif // __cplusplus <= 201103L + +#endif // _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS diff --git a/libstdc++-v3/testsuite/experimental/type_traits/value.cc b/libstdc++-v3/testsuite/experimental/type_traits/value.cc new file mode 100644 index 00000000000..b8d9fe1f950 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/type_traits/value.cc @@ -0,0 +1,324 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +using namespace std; +using namespace std::experimental; + +// These tests are rather simple, the front-end tests already test +// variable templates, and the library tests for the underlying +// traits are more elaborate. These are just simple sanity tests. + +static_assert(is_void_v && is_void::value, ""); +static_assert(!is_void_v && !is_void::value, ""); + +static_assert(is_null_pointer_v + && is_null_pointer::value, ""); +static_assert(!is_null_pointer_v + && !is_null_pointer::value, ""); + +static_assert(is_integral_v && is_integral::value, ""); +static_assert(!is_integral_v && !is_integral::value, ""); + +static_assert(is_floating_point_v + && is_floating_point::value, ""); +static_assert(!is_floating_point_v + && !is_floating_point::value, ""); + +static_assert(is_array_v && is_array::value, ""); +static_assert(!is_array_v && !is_array::value, ""); + +static_assert(is_pointer_v && is_pointer::value, ""); +static_assert(!is_pointer_v && !is_pointer::value, ""); + +static_assert(is_lvalue_reference_v + && is_lvalue_reference::value, ""); +static_assert(!is_lvalue_reference_v + && !is_lvalue_reference::value, ""); + +static_assert(is_rvalue_reference_v + && is_rvalue_reference::value, ""); +static_assert(!is_rvalue_reference_v + && !is_rvalue_reference::value, ""); + +struct EmptyFinal final {}; + +static_assert(is_member_object_pointer_v + && is_member_object_pointer::value, ""); +static_assert(!is_member_object_pointer_v + && !is_member_object_pointer::value, ""); + +static_assert(is_member_function_pointer_v + && is_member_function_pointer::value, ""); +static_assert(!is_member_function_pointer_v + && !is_member_function_pointer::value, ""); + +enum Enum {}; + +static_assert(is_enum_v && is_enum::value, ""); +static_assert(!is_enum_v && !is_enum::value, ""); + +union Union; + +static_assert(is_union_v && is_union::value, ""); +static_assert(!is_union_v && !is_union::value, ""); + +static_assert(is_class_v && is_class::value, ""); +static_assert(!is_class_v && !is_class::value, ""); + +static_assert(is_function_v && is_function::value, ""); +static_assert(!is_function_v && !is_function::value, ""); + +static_assert(is_reference_v && is_reference::value, ""); +static_assert(!is_reference_v && !is_reference::value, ""); + +static_assert(is_arithmetic_v && is_arithmetic::value, ""); +static_assert(!is_arithmetic_v && !is_arithmetic::value, ""); + +static_assert(is_fundamental_v && is_fundamental::value, ""); +static_assert(!is_fundamental_v + && !is_fundamental::value, ""); + +static_assert(is_object_v && is_object::value, ""); +static_assert(!is_object_v && !is_object::value, ""); + +static_assert(is_scalar_v && is_scalar::value, ""); +static_assert(!is_scalar_v && !is_scalar::value, ""); + +static_assert(is_compound_v + && is_compound::value, ""); +static_assert(!is_compound_v && !is_compound::value, ""); + +static_assert(is_member_pointer_v + && is_member_pointer::value, ""); +static_assert(!is_member_pointer_v + && !is_member_pointer::value, ""); + +static_assert(is_const_v && is_const::value, ""); +static_assert(!is_const_v && !is_const::value, ""); + +static_assert(is_volatile_v + && is_volatile::value, ""); +static_assert(!is_volatile_v && !is_volatile::value, ""); + +struct NType +{ + NType(int); + ~NType(); + int i; +private: + NType(const NType&); + NType& operator=(const NType&); + int i2; +}; + +static_assert(is_trivial_v && is_trivial::value, ""); +static_assert(!is_trivial_v && !is_trivial::value, ""); + +static_assert(is_trivially_copyable_v + && is_trivially_copyable::value, ""); +static_assert(!is_trivially_copyable_v + && !is_trivially_copyable::value, ""); + +static_assert(is_standard_layout_v + && is_standard_layout::value, ""); +static_assert(!is_standard_layout_v + && !is_standard_layout::value, ""); + +static_assert(is_pod_v + && is_pod::value, ""); +static_assert(!is_pod_v + && !is_pod::value, ""); + +static_assert(is_literal_type_v + && is_literal_type::value, ""); +static_assert(!is_literal_type_v + && !is_literal_type::value, ""); + +static_assert(is_empty_v + && is_empty::value, ""); +static_assert(!is_empty_v + && !is_empty::value, ""); + +struct Abstract {protected: virtual ~Abstract() = 0;}; +struct Poly : Abstract {virtual ~Poly();}; + +static_assert(is_polymorphic_v + && is_polymorphic::value, ""); +static_assert(!is_polymorphic_v + && !is_polymorphic::value, ""); + + + +static_assert(is_abstract_v + && is_abstract::value, ""); +static_assert(!is_abstract_v + && !is_abstract::value, ""); + +static_assert(is_final_v + && is_final::value, ""); +static_assert(!is_final_v + && !is_final::value, ""); + +static_assert(is_signed_v && is_signed::value, ""); +static_assert(!is_signed_v + && !is_signed::value, ""); + +static_assert(is_constructible_v + && is_constructible::value, ""); +static_assert(!is_constructible_v + && !is_constructible::value, ""); + +static_assert(is_default_constructible_v + && is_default_constructible::value, ""); +static_assert(!is_default_constructible_v + && !is_default_constructible::value, ""); + +static_assert(is_copy_constructible_v + && is_copy_constructible::value, ""); +static_assert(!is_copy_constructible_v + && !is_copy_constructible::value, ""); + +static_assert(is_move_constructible_v + && is_copy_constructible::value, ""); +static_assert(!is_move_constructible_v + && !is_copy_constructible::value, ""); + +static_assert(is_assignable_v + && is_assignable::value, ""); +static_assert(!is_assignable_v + && !is_assignable::value, ""); + +static_assert(is_copy_assignable_v + && is_copy_assignable::value, ""); +static_assert(!is_copy_assignable_v + && !is_copy_assignable::value, ""); + +static_assert(is_move_assignable_v + && is_move_assignable::value, ""); +static_assert(!is_move_assignable_v + && !is_move_assignable::value, ""); + +static_assert(is_destructible_v + && is_destructible::value, ""); +static_assert(!is_destructible_v + && !is_destructible::value, ""); + +static_assert(is_trivially_constructible_v + && is_trivially_constructible::value, ""); +static_assert(!is_trivially_constructible_v + && !is_trivially_constructible::value, ""); + +static_assert(is_trivially_default_constructible_v + && is_trivially_default_constructible::value, ""); +static_assert(!is_trivially_default_constructible_v + && !is_trivially_default_constructible::value, ""); + +static_assert(is_trivially_copy_constructible_v + && is_trivially_copy_constructible::value, ""); +static_assert(!is_trivially_copy_constructible_v + && !is_trivially_copy_constructible::value, ""); + +static_assert(is_trivially_move_constructible_v + && is_trivially_move_constructible::value, ""); +static_assert(!is_trivially_move_constructible_v + && !is_trivially_move_constructible::value, ""); + +static_assert(is_trivially_assignable_v + && is_trivially_assignable::value, ""); +static_assert(!is_trivially_assignable_v + && !is_trivially_assignable::value, ""); + +static_assert(is_trivially_copy_assignable_v + && is_trivially_copy_assignable::value, ""); +static_assert(!is_trivially_copy_assignable_v + && !is_trivially_copy_assignable::value, ""); + +static_assert(is_trivially_move_assignable_v + && is_trivially_move_assignable::value, ""); +static_assert(!is_trivially_move_assignable_v + && !is_trivially_move_assignable::value, ""); + +static_assert(is_trivially_destructible_v + && is_trivially_destructible::value, ""); +static_assert(!is_trivially_destructible_v + && !is_trivially_destructible::value, ""); + +static_assert(is_nothrow_constructible_v + && is_nothrow_constructible::value, ""); +static_assert(!is_nothrow_constructible_v + && !is_nothrow_constructible::value, ""); + +static_assert(is_nothrow_default_constructible_v + && is_nothrow_default_constructible::value, ""); +static_assert(!is_nothrow_default_constructible_v + && !is_nothrow_default_constructible::value, ""); + +static_assert(is_nothrow_copy_constructible_v + && is_nothrow_copy_constructible::value, ""); +static_assert(!is_nothrow_copy_constructible_v + && !is_nothrow_copy_constructible::value, ""); + +static_assert(is_nothrow_move_constructible_v + && is_nothrow_move_constructible::value, ""); +static_assert(!is_nothrow_move_constructible_v + && !is_nothrow_move_constructible::value, ""); + +static_assert(is_nothrow_assignable_v + && is_nothrow_assignable::value, ""); +static_assert(!is_nothrow_assignable_v + && !is_nothrow_assignable::value, ""); + +static_assert(is_nothrow_copy_assignable_v + && is_nothrow_copy_assignable::value, ""); +static_assert(!is_nothrow_copy_assignable_v + && !is_nothrow_copy_assignable::value, ""); + +static_assert(is_nothrow_move_assignable_v + && is_nothrow_move_assignable::value, ""); +static_assert(!is_nothrow_move_assignable_v + && !is_nothrow_move_assignable::value, ""); + +static_assert(has_virtual_destructor_v + && has_virtual_destructor::value, ""); +static_assert(!has_virtual_destructor_v + && !has_virtual_destructor::value, ""); + +static_assert(alignment_of_v == alignof(int) + && alignment_of::value == alignof(int) , ""); + +static_assert(rank_v == rank::value, ""); + +static_assert(extent_v == 2 + && extent::value == 2, ""); + +static_assert(is_same_v && is_same::value, ""); +static_assert(!is_same_v && !is_same::value, ""); + +static_assert(is_base_of_v + && is_base_of::value, ""); +static_assert(!is_base_of_v + && !is_base_of::value, ""); + +static_assert(is_convertible_v + && is_convertible::value, ""); +static_assert(!is_convertible_v + && !is_convertible::value, "");