diff options
author | ville <ville@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-11-03 08:41:40 +0000 |
---|---|---|
committer | ville <ville@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-11-03 08:41:40 +0000 |
commit | 610a7006caf1a911fb569212234051d314053a64 (patch) | |
tree | 9297e23ae61b087378aeec93b9b67501f63e547b /libstdc++-v3/include | |
parent | 6838a1945f592fcb79626fed83a74afdc0f190c2 (diff) | |
download | gcc-610a7006caf1a911fb569212234051d314053a64.tar.gz |
2015-11-03 Ville Voutilainen <ville.voutilainen@gmail.com>
Make the default constructors of tuple and pair conditionally explicit.
* include/std/type_traits (is_unsigned, __is_array_unknown_bounds,
__is_default_constructible_atom, __is_default_constructible_safe,
__is_direct_constructible_new_safe, __is_direct_constructible_ref_cast,
__is_nt_default_constructible_impl, is_nothrow_default_constructible,
is_nothrow_constructible, is_nothrow_assignable,
is_trivially_constructible, is_trivially_copy_constructible,
is_trivially_move_constructible, is_trivially_assignable,
is_trivially_copy_assignable, is_trivially_move_assignable,
is_trivially_destructible): Simplify.
* include/std/type_traits (
__do_is_implicitly_default_constructible_impl,
__is_implicitly_default_constructible_impl,
__is_implicitly_default_constructible_safe,
__is_implicitly_default_constructible): New.
* include/bits/stl_pair.h (pair::pair()): Use it.
* include/std/tuple (tuple<_T1, _T2>::tuple): Use it.
* include/std/tuple (_ImplicitlyDefaultConstructibleTuple): New.
* include/std/tuple (tuple<_Types...>::tuple()): Use it.
* testsuite/20_util/declval/requirements/1_neg.cc: Adjust.
* testsuite/20_util/is_implicitly_default_constructible/requirements/explicit_instantiation.cc: New.
* testsuite/20_util/is_implicitly_default_constructible/requirements/typedefs.cc: Likewise.
* testsuite/20_util/is_implicitly_default_constructible/value.cc: Likewise.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise.
* testsuite/20_util/pair/cons/explicit_construct.cc: Likewise.
* testsuite/20_util/tuple/cons/explicit_construct.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229699 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/stl_pair.h | 18 | ||||
-rw-r--r-- | libstdc++-v3/include/std/tuple | 35 | ||||
-rw-r--r-- | libstdc++-v3/include/std/type_traits | 64 |
3 files changed, 95 insertions, 22 deletions
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index a5a7898f2b7..dfcd357fb3c 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -141,13 +141,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template <typename _U1 = _T1, typename _U2 = _T2, typename enable_if<__and_< - is_default_constructible<_U1>, - is_default_constructible<_U2>> + __is_implicitly_default_constructible<_U1>, + __is_implicitly_default_constructible<_U2>> ::value, bool>::type = true> #endif _GLIBCXX_CONSTEXPR pair() : first(), second() { } +#if __cplusplus >= 201103L + template <typename _U1 = _T1, + typename _U2 = _T2, + typename enable_if<__and_< + is_default_constructible<_U1>, + is_default_constructible<_U2>, + __not_< + __and_<__is_implicitly_default_constructible<_U1>, + __is_implicitly_default_constructible<_U2>>>> + ::value, bool>::type = false> + explicit constexpr pair() + : first(), second() { } +#endif + /** Two objects may be passed to a @c pair constructor to be copied. */ #if __cplusplus < 201103L pair(const _T1& __a, const _T2& __b) diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 8af01f4756e..e6c32b348be 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -551,16 +551,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __and_<is_default_constructible<_Elements>...>::value; } + static constexpr bool _ImplicitlyDefaultConstructibleTuple() + { + return __and_<__is_implicitly_default_constructible<_Elements>...> + ::value; + } }; public: template<typename _Dummy = void, typename enable_if<_TC2<_Dummy>:: - _DefaultConstructibleTuple(), + _ImplicitlyDefaultConstructibleTuple(), bool>::type = true> constexpr tuple() : _Inherited() { } + template<typename _Dummy = void, + typename enable_if<_TC2<_Dummy>:: + _DefaultConstructibleTuple() + && + !_TC2<_Dummy>:: + _ImplicitlyDefaultConstructibleTuple(), + bool>::type = false> + explicit constexpr tuple() + : _Inherited() { } + // Shortcut for the cases where constructors taking _Elements... // need to be constrained. template<typename _Dummy> using _TCC = @@ -837,13 +852,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template <typename _U1 = _T1, typename _U2 = _T2, typename enable_if<__and_< - is_default_constructible<_U1>, - is_default_constructible<_U2>> + __is_implicitly_default_constructible<_U1>, + __is_implicitly_default_constructible<_U2>> ::value, bool>::type = true> constexpr tuple() : _Inherited() { } + template <typename _U1 = _T1, + typename _U2 = _T2, + typename enable_if< + __and_< + is_default_constructible<_U1>, + is_default_constructible<_U2>, + __not_< + __and_<__is_implicitly_default_constructible<_U1>, + __is_implicitly_default_constructible<_U2>>>> + ::value, bool>::type = false> + + explicit constexpr tuple() + : _Inherited() { } + // Shortcut for the cases where constructors taking _T1, _T2 // need to be constrained. template<typename _Dummy> using _TCC = diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e08131b2c6d..7448d5b836f 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -715,7 +715,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_unsigned template<typename _Tp> struct is_unsigned - : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type + : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>> { }; @@ -744,7 +744,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp> struct __is_array_unknown_bounds - : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type + : public __and_<is_array<_Tp>, __not_<extent<_Tp>>> { }; // In N3290 is_destructible does not say anything about function @@ -862,7 +862,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp> struct __is_default_constructible_atom : public __and_<__not_<is_void<_Tp>>, - __is_default_constructible_impl<_Tp>>::type + __is_default_constructible_impl<_Tp>> { }; template<typename _Tp, bool = is_array<_Tp>::value> @@ -877,7 +877,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_default_constructible_safe<_Tp, true> : public __and_<__is_array_known_bounds<_Tp>, __is_default_constructible_atom<typename - remove_all_extents<_Tp>::type>>::type + remove_all_extents<_Tp>::type>> { }; template<typename _Tp> @@ -957,7 +957,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename _Arg> struct __is_direct_constructible_new_safe : public __and_<is_destructible<_Tp>, - __is_direct_constructible_impl<_Tp, _Arg>>::type + __is_direct_constructible_impl<_Tp, _Arg>> { }; template<typename, typename> @@ -1029,7 +1029,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __and_<__is_static_castable<_Arg, _Tp>, __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>, __is_lvalue_to_rvalue_ref<_Arg, _Tp> - >>>::type + >>> { }; template<typename _Tp, typename _Arg> @@ -1144,7 +1144,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_nt_default_constructible_impl<_Tp, true> : public __and_<__is_array_known_bounds<_Tp>, __is_nt_default_constructible_atom<typename - remove_all_extents<_Tp>::type>>::type + remove_all_extents<_Tp>::type>> { }; template<typename _Tp> @@ -1156,7 +1156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp> struct is_nothrow_default_constructible : public __and_<is_default_constructible<_Tp>, - __is_nt_default_constructible_impl<_Tp>>::type + __is_nt_default_constructible_impl<_Tp>> { }; template<typename _Tp, typename... _Args> @@ -1179,7 +1179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename... _Args> struct is_nothrow_constructible : public __and_<is_constructible<_Tp, _Args...>, - __is_nt_constructible_impl<_Tp, _Args...>>::type + __is_nt_constructible_impl<_Tp, _Args...>> { }; template<typename _Tp, bool = __is_referenceable<_Tp>::value> @@ -1285,7 +1285,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename _Up> struct is_nothrow_assignable : public __and_<is_assignable<_Tp, _Up>, - __is_nt_assignable_impl<_Tp, _Up>>::type + __is_nt_assignable_impl<_Tp, _Up>> { }; template<typename _Tp, bool = __is_referenceable<_Tp>::value> @@ -1328,7 +1328,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename... _Args> struct is_trivially_constructible : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool, - __is_trivially_constructible(_Tp, _Args...)>>::type + __is_trivially_constructible(_Tp, _Args...)>> { }; /// is_trivially_default_constructible @@ -1337,12 +1337,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public is_trivially_constructible<_Tp>::type { }; + struct __do_is_implicitly_default_constructible_impl + { + template <typename _Tp> + static void __helper(const _Tp&); + + template <typename _Tp> + static true_type __test(const _Tp&, + decltype(__helper<const _Tp&>({}))* = 0); + + static false_type __test(...); + }; + + template<typename _Tp> + struct __is_implicitly_default_constructible_impl + : public __do_is_implicitly_default_constructible_impl + { + typedef decltype(__test(declval<_Tp>())) type; + }; + + template<typename _Tp> + struct __is_implicitly_default_constructible_safe + : public __is_implicitly_default_constructible_impl<_Tp>::type + { }; + + template <typename _Tp> + struct __is_implicitly_default_constructible + : public __and_<is_default_constructible<_Tp>, + __is_implicitly_default_constructible_safe<_Tp>> + { }; + /// is_trivially_copy_constructible template<typename _Tp> struct is_trivially_copy_constructible : public __and_<is_copy_constructible<_Tp>, integral_constant<bool, - __is_trivially_constructible(_Tp, const _Tp&)>>::type + __is_trivially_constructible(_Tp, const _Tp&)>> { }; /// is_trivially_move_constructible @@ -1350,7 +1380,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_trivially_move_constructible : public __and_<is_move_constructible<_Tp>, integral_constant<bool, - __is_trivially_constructible(_Tp, _Tp&&)>>::type + __is_trivially_constructible(_Tp, _Tp&&)>> { }; /// is_trivially_assignable @@ -1358,7 +1388,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_trivially_assignable : public __and_<is_assignable<_Tp, _Up>, integral_constant<bool, - __is_trivially_assignable(_Tp, _Up)>>::type + __is_trivially_assignable(_Tp, _Up)>> { }; /// is_trivially_copy_assignable @@ -1366,7 +1396,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_trivially_copy_assignable : public __and_<is_copy_assignable<_Tp>, integral_constant<bool, - __is_trivially_assignable(_Tp&, const _Tp&)>>::type + __is_trivially_assignable(_Tp&, const _Tp&)>> { }; /// is_trivially_move_assignable @@ -1374,14 +1404,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_trivially_move_assignable : public __and_<is_move_assignable<_Tp>, integral_constant<bool, - __is_trivially_assignable(_Tp&, _Tp&&)>>::type + __is_trivially_assignable(_Tp&, _Tp&&)>> { }; /// is_trivially_destructible template<typename _Tp> struct is_trivially_destructible : public __and_<is_destructible<_Tp>, integral_constant<bool, - __has_trivial_destructor(_Tp)>>::type + __has_trivial_destructor(_Tp)>> { }; /// has_trivial_default_constructor (temporary legacy) |