Define std::owner_less<void> specialization (P0074R0)

* include/bits/shared_ptr.h (owner_less): Add default template
	argument.
	* include/bits/shared_ptr_base.h (_Sp_owner_less<void, void>): Define
	specialization.
	(owner_less<void>): 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
This commit is contained in:
Jonathan Wakely 2016-08-03 19:11:18 +01:00 committed by Jonathan Wakely
parent 068c8ac17c
commit b7dabce5f3
6 changed files with 79 additions and 4 deletions

View File

@ -1,5 +1,15 @@
2016-08-03 Jonathan Wakely <jwakely@redhat.com>
* include/bits/shared_ptr.h (owner_less): Add default template
argument.
* include/bits/shared_ptr_base.h (_Sp_owner_less<void, void>): Define
specialization.
(owner_less<void>): 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.

View File

@ -535,9 +535,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Primary template owner_less
template<typename _Tp>
template<typename _Tp = void>
struct owner_less;
/// Void specialization of owner_less
template<>
struct owner_less<void> : _Sp_owner_less<void, void>
{ };
/// Partial specialization of owner_less for shared_ptr.
template<typename _Tp>
struct owner_less<shared_ptr<_Tp>>

View File

@ -1506,6 +1506,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.owner_before(__rhs); }
};
template<>
struct _Sp_owner_less<void, void>
{
template<typename _Tp, typename _Up>
auto
operator()(const _Tp& __lhs, const _Up& __rhs) const
-> decltype(__lhs.owner_before(__rhs))
{ return __lhs.owner_before(__rhs); }
using is_transparent = void;
};
template<typename _Tp, _Lock_policy _Lp>
struct owner_less<__shared_ptr<_Tp, _Lp>>
: public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>

View File

@ -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<void>

View File

@ -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
// <http://www.gnu.org/licenses/>.
// { dg-do compile { target c++11 } }
#include <memory>
#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<>, owner_less<void>>::value,
"owner_less<> uses void specialization");
shared_ptr<int> sp1;
shared_ptr<void> sp2;
shared_ptr<long> sp3;
weak_ptr<int> wp1;
owner_less<> cmp;
cmp(sp1, sp2);
cmp(sp1, wp1);
cmp(sp1, sp3);
cmp(wp1, sp1);
cmp(wp1, wp1);
}

View File

@ -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