
This change moves the definitions of feature test macros (or strictly speaking, the requests for <bits/version.h> to define them) so that only standard headers define them. For example, <bits/shared_ptr.h> will no longer define macros related to std::shared_ptr, only <memory> and <version> will define them. This means that __cpp_lib_shared_ptr_arrays will not be defined by <future> or by other headers that include <bits/shared_ptr.h>. It will only be defined when <memory> has been included. This will discourage users from relying on transitive includes. As a result, internal headers that need to query the macros should use the internal macros like __glibcxx_shared_ptr_arrays instead of __cpp_lib_shared_ptr_arrays, as those internal macros are defined by the internal headers after icluding <bits/version.h>. There are some exceptions to this rule, because __cpp_lib_is_constant_evaluated is defined by bits/c++config.h and so is available everywhere, and __cpp_lib_three_way_comparison is defined by <compare> which several headers are explicitly specified to include, so its macro is guaranteed to be usable too. N.B. not many internal headers actually need an explicit include of <bits/version.h>, because most of them include <type_traits> and so get all the __glibcxx_foo internal macros from there. libstdc++-v3/ChangeLog: * include/bits/algorithmfwd.h: Do not define standard feature test macro here. * include/bits/align.h: Likewise. Test internal macros instead of standard macros. * include/bits/alloc_traits.h: Likewise. * include/bits/allocator.h: Likewise. * include/bits/atomic_base.h: Likewise. * include/bits/atomic_timed_wait.h: Likewise. * include/bits/atomic_wait.h: Likewise. * include/bits/basic_string.h: Likewise. * include/bits/basic_string.tcc: Likewise. * include/bits/char_traits.h: Likewise. * include/bits/chrono.h: Likewise. * include/bits/cow_string.h: Likewise. * include/bits/forward_list.h: Likewise. * include/bits/hashtable.h: Likewise. * include/bits/ios_base.h: Likewise. * include/bits/memory_resource.h: Likewise. * include/bits/move.h: Likewise. * include/bits/move_only_function.h: Likewise. * include/bits/node_handle.h: Likewise. * include/bits/ptr_traits.h: Likewise. * include/bits/range_access.h: Likewise. * include/bits/ranges_algo.h: Likewise. * include/bits/ranges_cmp.h: Likewise. * include/bits/ranges_util.h: Likewise. * include/bits/semaphore_base.h: Likewise. * include/bits/shared_ptr.h: Likewise. * include/bits/shared_ptr_atomic.h: Likewise. * include/bits/shared_ptr_base.h: Likewise. * include/bits/stl_algo.h: Likewise. * include/bits/stl_algobase.h: Likewise. * include/bits/stl_function.h: Likewise. * include/bits/stl_iterator.h: Likewise. * include/bits/stl_list.h: Likewise. * include/bits/stl_map.h: Likewise. * include/bits/stl_pair.h: Likewise. * include/bits/stl_queue.h: Likewise. * include/bits/stl_stack.h: Likewise. * include/bits/stl_tree.h: Likewise. * include/bits/stl_uninitialized.h: Likewise. * include/bits/stl_vector.h: Likewise. * include/bits/unique_ptr.h: Likewise. * include/bits/unordered_map.h: Likewise. * include/bits/uses_allocator_args.h: Likewise. * include/bits/utility.h: Likewise. * include/bits/erase_if.h: Add comment. * include/std/algorithm: Define standard feature test macros here. * include/std/atomic: Likewise. * include/std/array: Likewise. * include/std/chrono: Likewise. * include/std/condition_variable: Likewise. * include/std/deque: Likewise. * include/std/format: Likewise. * include/std/functional: Likewise. * include/std/forward_list: Likewise. * include/std/ios: Likewise. * include/std/iterator: Likewise. * include/std/list: Likewise. * include/std/map: Likewise. * include/std/memory: Likewise. * include/std/numeric: Likewise. * include/std/queue: Likewise. * include/std/ranges: Likewise. * include/std/regex: Likewise. * include/std/set: Likewise. * include/std/stack: Likewise. * include/std/stop_token: Likewise. * include/std/string: Likewise. * include/std/string_view: * include/std/tuple: Likewise. * include/std/unordered_map: * include/std/unordered_set: * include/std/utility: Likewise. * include/std/vector: Likewise. * include/std/scoped_allocator: Query internal macros instead of standard macros.
155 lines
4.9 KiB
C++
155 lines
4.9 KiB
C++
// <vector> -*- C++ -*-
|
|
|
|
// Copyright (C) 2001-2023 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
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
/*
|
|
*
|
|
* Copyright (c) 1994
|
|
* Hewlett-Packard Company
|
|
*
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
* provided that the above copyright notice appear in all copies and
|
|
* that both that copyright notice and this permission notice appear
|
|
* in supporting documentation. Hewlett-Packard Company makes no
|
|
* representations about the suitability of this software for any
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
*
|
|
*
|
|
* Copyright (c) 1996
|
|
* Silicon Graphics Computer Systems, Inc.
|
|
*
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
* provided that the above copyright notice appear in all copies and
|
|
* that both that copyright notice and this permission notice appear
|
|
* in supporting documentation. Silicon Graphics makes no
|
|
* representations about the suitability of this software for any
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
*/
|
|
|
|
/** @file include/vector
|
|
* This is a Standard C++ Library header.
|
|
*/
|
|
|
|
#ifndef _GLIBCXX_VECTOR
|
|
#define _GLIBCXX_VECTOR 1
|
|
|
|
#pragma GCC system_header
|
|
|
|
#include <bits/requires_hosted.h> // container
|
|
|
|
#include <bits/stl_algobase.h>
|
|
#include <bits/allocator.h>
|
|
#include <bits/stl_construct.h>
|
|
#include <bits/stl_uninitialized.h>
|
|
#include <bits/stl_vector.h>
|
|
#include <bits/stl_bvector.h>
|
|
#include <bits/refwrap.h>
|
|
#include <bits/range_access.h>
|
|
|
|
#ifndef _GLIBCXX_EXPORT_TEMPLATE
|
|
# include <bits/vector.tcc>
|
|
#endif
|
|
|
|
#ifdef _GLIBCXX_DEBUG
|
|
# include <debug/vector>
|
|
#endif
|
|
|
|
#define __glibcxx_want_constexpr_vector
|
|
#define __glibcxx_want_erase_if
|
|
#define __glibcxx_want_incomplete_container_elements
|
|
#define __glibcxx_want_nonmember_container_access
|
|
#include <bits/version.h>
|
|
|
|
#if __cplusplus >= 201703L
|
|
#include <bits/memory_resource.h>
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
{
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
namespace pmr {
|
|
template<typename _Tp>
|
|
using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
|
|
} // namespace pmr
|
|
# ifdef _GLIBCXX_DEBUG
|
|
namespace _GLIBCXX_STD_C::pmr {
|
|
template<typename _Tp>
|
|
using vector
|
|
= _GLIBCXX_STD_C::vector<_Tp, std::pmr::polymorphic_allocator<_Tp>>;
|
|
} // namespace _GLIBCXX_STD_C::pmr
|
|
# endif
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
} // namespace std
|
|
#endif // C++17
|
|
|
|
#ifdef __cpp_lib_erase_if // C++ >= 20 && HOSTED
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
{
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
template<typename _Tp, typename _Alloc, typename _Predicate>
|
|
_GLIBCXX20_CONSTEXPR
|
|
inline typename vector<_Tp, _Alloc>::size_type
|
|
erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred)
|
|
{
|
|
using namespace __gnu_cxx;
|
|
_GLIBCXX_STD_C::vector<_Tp, _Alloc>& __ucont = __cont;
|
|
const auto __osz = __cont.size();
|
|
const auto __end = __ucont.end();
|
|
auto __removed = std::__remove_if(__ucont.begin(), __end,
|
|
__ops::__pred_iter(std::ref(__pred)));
|
|
if (__removed != __end)
|
|
{
|
|
__cont.erase(__niter_wrap(__cont.begin(), __removed),
|
|
__cont.end());
|
|
return __osz - __cont.size();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
template<typename _Tp, typename _Alloc, typename _Up>
|
|
_GLIBCXX20_CONSTEXPR
|
|
inline typename vector<_Tp, _Alloc>::size_type
|
|
erase(vector<_Tp, _Alloc>& __cont, const _Up& __value)
|
|
{
|
|
using namespace __gnu_cxx;
|
|
_GLIBCXX_STD_C::vector<_Tp, _Alloc>& __ucont = __cont;
|
|
const auto __osz = __cont.size();
|
|
const auto __end = __ucont.end();
|
|
auto __removed = std::__remove_if(__ucont.begin(), __end,
|
|
__ops::__iter_equals_val(__value));
|
|
if (__removed != __end)
|
|
{
|
|
__cont.erase(__niter_wrap(__cont.begin(), __removed),
|
|
__cont.end());
|
|
return __osz - __cont.size();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
} // namespace std
|
|
#endif // __cpp_lib_erase_if
|
|
|
|
#endif /* _GLIBCXX_VECTOR */
|