This is a followup to r194536, which changed the pair copy constructor to be

trivial in C++03, thus making it trivial in both C++03 and C++11.

This patch allows one to opt-in/out of this decision with a macro.  You can
choose to have the pair copy constructor always be trivial, or always be
non-trivial.  The flag controlling this is now _LIBCPP_TRIVIAL_PAIR_COPY_CTOR.

The client can define this flag to 1, and the pair copy constructor will be
trivial (when possible of course), or to 0, and the pair copy constructor will
be nontrivial.

Default settings for this flag are set in <__config> (as usual).  With this
commit the default is _LIBCPP_TRIVIAL_PAIR_COPY_CTOR=1 for all platforms
except __APPLE__, which defaults to _LIBCPP_TRIVIAL_PAIR_COPY_CTOR=0.

llvm-svn: 194742
This commit is contained in:
Howard Hinnant 2013-11-14 22:52:25 +00:00
parent ae78e23e5f
commit f9fd0d6d11
2 changed files with 12 additions and 2 deletions

View File

@ -567,6 +567,16 @@ template <unsigned> struct __static_assert_check {};
#define _LIBCPP_WCTYPE_IS_MASK
#endif
#if defined(__APPLE__)
#ifndef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
# define _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 0
#endif
#endif
#ifndef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
# define _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 1
#endif
#ifndef _LIBCPP_STD_VER
# if __cplusplus <= 201103L
# define _LIBCPP_STD_VER 11

View File

@ -272,10 +272,10 @@ struct _LIBCPP_TYPE_VIS_ONLY pair
)
: first(__p.first), second(__p.second) {}
#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
#if !defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
_LIBCPP_INLINE_VISIBILITY
pair(const pair& __p) = default;
#elif !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) // default the copy ctor in C++03
#elif !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) || !_LIBCPP_TRIVIAL_PAIR_COPY_CTOR
_LIBCPP_INLINE_VISIBILITY
pair(const pair& __p)
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&