From b7dabce5f3a4f3b3468181a1cba0ef690f8855bd Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 3 Aug 2016 19:11:18 +0100 Subject: [PATCH] Define std::owner_less specialization (P0074R0) * include/bits/shared_ptr.h (owner_less): Add default template argument. * include/bits/shared_ptr_base.h (_Sp_owner_less): Define specialization. (owner_less): Define specialization. * include/bits/stl_function.h (__cpp_lib_transparent_operators): Update value. * testsuite/20_util/owner_less/void.cc: New test. * testsuite/experimental/feat-cxx14.cc: Update macro value tested. From-SVN: r239089 --- libstdc++-v3/ChangeLog | 10 ++++ libstdc++-v3/include/bits/shared_ptr.h | 7 ++- libstdc++-v3/include/bits/shared_ptr_base.h | 12 +++++ libstdc++-v3/include/bits/stl_function.h | 2 +- .../testsuite/20_util/owner_less/void.cc | 48 +++++++++++++++++++ .../testsuite/experimental/feat-cxx14.cc | 4 +- 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/owner_less/void.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 61135055e37..8bc5b2e7176 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,15 @@ 2016-08-03 Jonathan Wakely + * include/bits/shared_ptr.h (owner_less): Add default template + argument. + * include/bits/shared_ptr_base.h (_Sp_owner_less): Define + specialization. + (owner_less): Define specialization. + * include/bits/stl_function.h (__cpp_lib_transparent_operators): + Update value. + * testsuite/20_util/owner_less/void.cc: New test. + * testsuite/experimental/feat-cxx14.cc: Update macro value tested. + * include/bits/allocator.h (__cpp_lib_incomplete_container_elements): Define feature-test macro. * include/bits/range_access.h (__cpp_lib_array_constexpr): Likewise. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index b22477e96b2..16f78f7968a 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -535,9 +535,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Primary template owner_less - template + template struct owner_less; + /// Void specialization of owner_less + template<> + struct owner_less : _Sp_owner_less + { }; + /// Partial specialization of owner_less for shared_ptr. template struct owner_less> diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index e844c9c91fe..1474df603b7 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1506,6 +1506,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.owner_before(__rhs); } }; + template<> + struct _Sp_owner_less + { + template + auto + operator()(const _Tp& __lhs, const _Up& __rhs) const + -> decltype(__lhs.owner_before(__rhs)) + { return __lhs.owner_before(__rhs); } + + using is_transparent = void; + }; + template struct owner_less<__shared_ptr<_Tp, _Lp>> : public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>> diff --git a/libstdc++-v3/include/bits/stl_function.h b/libstdc++-v3/include/bits/stl_function.h index 68f39ff2690..1408da6e37e 100644 --- a/libstdc++-v3/include/bits/stl_function.h +++ b/libstdc++-v3/include/bits/stl_function.h @@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201103L -#define __cpp_lib_transparent_operators 201210 +#define __cpp_lib_transparent_operators 201510 template<> struct plus diff --git a/libstdc++-v3/testsuite/20_util/owner_less/void.cc b/libstdc++-v3/testsuite/20_util/owner_less/void.cc new file mode 100644 index 00000000000..4facbf57001 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/owner_less/void.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2016 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 copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++11 } } + +#include + +#if __cplusplus >= 201402L +// The feature-test macro is only defined for C++14 and later. +# if __cpp_lib_transparent_operators < 201510 +# error "__cpp_lib_transparent_operators < 201510" +# endif +#endif + +void +test01() +{ + using namespace std; + + static_assert(is_same, owner_less>::value, + "owner_less<> uses void specialization"); + + shared_ptr sp1; + shared_ptr sp2; + shared_ptr sp3; + weak_ptr wp1; + + owner_less<> cmp; + cmp(sp1, sp2); + cmp(sp1, wp1); + cmp(sp1, sp3); + cmp(wp1, sp1); + cmp(wp1, wp1); +} diff --git a/libstdc++-v3/testsuite/experimental/feat-cxx14.cc b/libstdc++-v3/testsuite/experimental/feat-cxx14.cc index 42b633f6ef6..c61f7b00f68 100644 --- a/libstdc++-v3/testsuite/experimental/feat-cxx14.cc +++ b/libstdc++-v3/testsuite/experimental/feat-cxx14.cc @@ -40,8 +40,8 @@ #ifndef __cpp_lib_transparent_operators # error "__cpp_lib_transparent_operators" -#elif __cpp_lib_transparent_operators != 201210 -# error "__cpp_lib_transparent_operators != 201210" +#elif __cpp_lib_transparent_operators < 201210 +# error "__cpp_lib_transparent_operators < 201210" #endif #ifndef __cpp_lib_result_of_sfinae -- 2.30.2