From f3aed3698185dd4a03b210a9d73be4dc1efc580f Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Thu, 6 Jan 2022 12:36:07 +0100 Subject: [PATCH] [libc++] Implement P1425R4 (Iterator pair constructors for std::stack and std::queue) Implement P1425R4 Reviewed By: Quuxplusone, #libc, Mordante Spies: Mordante, jloser, libcxx-commits, arichardson Differential Revision: https://reviews.llvm.org/D115977 --- libcxx/docs/FeatureTestMacroTable.rst | 2 + libcxx/docs/Status/Cxx2bPapers.csv | 2 +- libcxx/include/queue | 44 +++++++++++++- libcxx/include/stack | 43 ++++++++++++- libcxx/include/version | 2 + .../queue.cons.alloc/ctor_iterators.pass.cpp | 48 +++++++++++++++ .../queue/queue.cons/ctor_iterators.pass.cpp | 44 ++++++++++++++ .../queue/queue.cons/deduct.pass.cpp | 36 +++++++---- .../stack.cons.alloc/ctor_iterators.pass.cpp | 48 +++++++++++++++ .../stack/stack.cons/ctor_iterators.pass.cpp | 43 +++++++++++++ .../stack/stack.cons/deduct.pass.cpp | 36 ++++++++--- .../queue.version.pass.cpp | 60 +++++++++++++++++++ .../stack.version.pass.cpp | 60 +++++++++++++++++++ .../version.version.pass.cpp | 24 ++++++++ .../generate_feature_test_macro_components.py | 4 ++ 15 files changed, 474 insertions(+), 22 deletions(-) create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_iterators.pass.cpp create mode 100644 libcxx/test/std/language.support/support.limits/support.limits.general/queue.version.pass.cpp create mode 100644 libcxx/test/std/language.support/support.limits/support.limits.general/stack.version.pass.cpp diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst index 714ed803ba69..40e755864c19 100644 --- a/libcxx/docs/FeatureTestMacroTable.rst +++ b/libcxx/docs/FeatureTestMacroTable.rst @@ -296,6 +296,8 @@ Status ------------------------------------------------- ----------------- **C++ 2b** ------------------------------------------------------------------- + ``__cpp_lib_adaptor_iterator_pair_constructor`` ``202106L`` + ------------------------------------------------- ----------------- ``__cpp_lib_allocate_at_least`` *unimplemented* ------------------------------------------------- ----------------- ``__cpp_lib_associative_heterogeneous_erasure`` *unimplemented* diff --git a/libcxx/docs/Status/Cxx2bPapers.csv b/libcxx/docs/Status/Cxx2bPapers.csv index 7a76e1f57645..50b11c4347d8 100644 --- a/libcxx/docs/Status/Cxx2bPapers.csv +++ b/libcxx/docs/Status/Cxx2bPapers.csv @@ -15,7 +15,7 @@ "`P0448R4 `__","LWG","A strstream replacement using span as buffer","June 2021","","" "`P1132R8 `__","LWG","out_ptr - a scalable output pointer abstraction","June 2021","","" "`P1328R1 `__","LWG","Making std::type_info::operator== constexpr","June 2021","","" -"`P1425R4 `__","LWG","Iterators pair constructors for stack and queue","June 2021","","" +"`P1425R4 `__","LWG","Iterators pair constructors for stack and queue","June 2021","|Complete|","14.0" "`P1518R2 `__","LWG","Stop overconstraining allocators in container deduction guides","June 2021","|Complete|","13.0" "`P1659R3 `__","LWG","starts_with and ends_with","June 2021","","" "`P1951R1 `__","LWG","Default Arguments for pair Forwarding Constructor","June 2021","|Complete|","14.0" diff --git a/libcxx/include/queue b/libcxx/include/queue index 9fad80253c50..9e1257b25e0e 100644 --- a/libcxx/include/queue +++ b/libcxx/include/queue @@ -41,6 +41,8 @@ public: explicit queue(const container_type& c); explicit queue(container_type&& c) + template + queue(InputIterator first, InputIterator last); // since C++23 template explicit queue(const Alloc& a); template @@ -51,6 +53,8 @@ public: queue(const queue& q, const Alloc& a); template queue(queue&& q, const Alloc& a); + template + queue(InputIterator first, InputIterator last, const Alloc&); // since C++23 bool empty() const; size_type size() const; @@ -71,9 +75,17 @@ public: template queue(Container) -> queue; // C++17 +template + queue(InputIterator, InputIterator) -> queue>; // since C++23 + template queue(Container, Allocator) -> queue; // C++17 +template + queue(InputIterator, InputIterator, Allocator) + -> queue, + deque, Allocator>>; // since C++23 + template bool operator==(const queue& x,const queue& y); @@ -206,12 +218,14 @@ template */ #include <__config> +#include <__iterator/iterator_traits.h> #include <__memory/uses_allocator.h> #include <__utility/forward.h> #include #include #include #include +#include #include #include @@ -256,6 +270,20 @@ public: _LIBCPP_INLINE_VISIBILITY queue(const queue& __q) : c(__q.c) {} +#if _LIBCPP_STD_VER > 20 + template ::value>> + _LIBCPP_HIDE_FROM_ABI + queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} + + template ::value>, + class = __enable_if_t::value>> + _LIBCPP_HIDE_FROM_ABI + queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc) : c(__first, __second, __alloc) {} +#endif + _LIBCPP_INLINE_VISIBILITY queue& operator=(const queue& __q) {c = __q.c; return *this;} @@ -359,7 +387,7 @@ public: operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); }; -#if _LIBCPP_STD_VER >= 17 +#if _LIBCPP_STD_VER > 14 template::value> > @@ -375,6 +403,20 @@ queue(_Container, _Alloc) -> queue; #endif +#if _LIBCPP_STD_VER > 20 +template ::value>> +queue(_InputIterator, _InputIterator) + -> queue<__iter_value_type<_InputIterator>>; + +template ::value>, + class = __enable_if_t<__is_allocator<_Alloc>::value>> +queue(_InputIterator, _InputIterator, _Alloc) + -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>; +#endif + template inline _LIBCPP_INLINE_VISIBILITY bool diff --git a/libcxx/include/stack b/libcxx/include/stack index 3cf6cd233282..ad65d7b29b4f 100644 --- a/libcxx/include/stack +++ b/libcxx/include/stack @@ -41,11 +41,14 @@ public: explicit stack(const container_type& c); explicit stack(container_type&& c); + template stack(InputIterator first, InputIterator last); // since C++23 template explicit stack(const Alloc& a); template stack(const container_type& c, const Alloc& a); template stack(container_type&& c, const Alloc& a); template stack(const stack& c, const Alloc& a); template stack(stack&& c, const Alloc& a); + template + stack(InputIterator first, InputIterator last, const Alloc&); // since C++23 bool empty() const; size_type size() const; @@ -63,9 +66,17 @@ public: template stack(Container) -> stack; // C++17 +template + stack(InputIterator, InputIterator) -> stack>; // since C++23 + template stack(Container, Allocator) -> stack; // C++17 +template + stack(InputIterator, InputIterator, Allocator) + -> stack, + deque, Allocator>>; // since C++23 + template bool operator==(const stack& x, const stack& y); template @@ -88,9 +99,11 @@ template */ #include <__config> +#include <__iterator/iterator_traits.h> #include <__memory/uses_allocator.h> #include <__utility/forward.h> #include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -184,6 +197,20 @@ public: : c(_VSTD::move(__s.c), __a) {} #endif // _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 20 + template ::value>> + _LIBCPP_HIDE_FROM_ABI + stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} + + template ::value>, + class = __enable_if_t::value>> + _LIBCPP_HIDE_FROM_ABI + stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc) : c(__first, __last, __alloc) {} +#endif + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY @@ -232,7 +259,7 @@ public: operator< (const stack& __x, const stack& __y); }; -#if _LIBCPP_STD_VER >= 17 +#if _LIBCPP_STD_VER > 14 template::value> > @@ -248,6 +275,20 @@ stack(_Container, _Alloc) -> stack; #endif +#if _LIBCPP_STD_VER > 20 +template::value>> +stack(_InputIterator, _InputIterator) + -> stack<__iter_value_type<_InputIterator>>; + +template::value>, + class = __enable_if_t<__is_allocator<_Alloc>::value>> +stack(_InputIterator, _InputIterator, _Alloc) + -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>; +#endif + template inline _LIBCPP_INLINE_VISIBILITY bool diff --git a/libcxx/include/version b/libcxx/include/version index db67b2e65167..6774e3151a6c 100644 --- a/libcxx/include/version +++ b/libcxx/include/version @@ -14,6 +14,7 @@ version synopsis Macro name Value Headers +__cpp_lib_adaptor_iterator_pair_constructor 202106L __cpp_lib_addressof_constexpr 201603L __cpp_lib_allocate_at_least 202106L __cpp_lib_allocator_traits_is_always_equal 201411L @@ -358,6 +359,7 @@ __cpp_lib_void_t 201411L #endif #if _LIBCPP_STD_VER > 20 +# define __cpp_lib_adaptor_iterator_pair_constructor 202106L // # define __cpp_lib_allocate_at_least 202106L // # define __cpp_lib_associative_heterogeneous_erasure 202110L # define __cpp_lib_byteswap 202110L diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_iterators.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_iterators.pass.cpp new file mode 100644 index 000000000000..90606643b933 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_iterators.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// + +// template +// queue(InputIterator, InputIterator, const Allocator&); + +#include +#include + +#include "test_allocator.h" + +using base_type = std::queue>>; + +class GetAlloc : public base_type { + test_allocator_statistics* stats; + +public: + explicit GetAlloc(test_allocator_statistics& stats_, const int* begin, const int* end) + : base_type(begin, end, test_allocator(&stats_)), stats(&stats_) {} + void check() { + assert(size() == 4); + assert(stats->alloc_count > 0); + } +}; + +int main(int, char**) { + const int a[] = {4, 3, 2, 1}; + test_allocator_statistics stats{}; + GetAlloc queue(stats, a, a + 4); + assert(queue.front() == 4); + queue.pop(); + assert(queue.front() == 3); + queue.pop(); + assert(queue.front() == 2); + queue.pop(); + assert(queue.front() == 1); + queue.pop(); + assert(queue.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_iterators.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_iterators.pass.cpp new file mode 100644 index 000000000000..192587ca3f5a --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_iterators.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// + +// template +// queue(InputIterator, InputIterator); + +#include +#include +#include + +#include "test_allocator.h" + +static_assert(!std::is_constructible_v, int, int, std::allocator>); +static_assert(!std::is_constructible_v, int*, int*, int>); +static_assert( std::is_constructible_v>>, int*, int*, test_allocator>); +static_assert(!std::is_constructible_v>>, int*, int*, std::allocator>); + +struct alloc : test_allocator { + alloc(test_allocator_statistics* a); +}; +static_assert( std::is_constructible_v>, int*, int*, test_allocator_statistics*>); + +int main(int, char**) { + const int a[] = {4, 3, 2, 1}; + std::queue queue(a, a + 4); + assert(queue.front() == 4); + queue.pop(); + assert(queue.front() == 3); + queue.pop(); + assert(queue.front() == 2); + queue.pop(); + assert(queue.front() == 1); + queue.pop(); + assert(queue.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/deduct.pass.cpp index a30d11fd493f..e17c39e5faff 100644 --- a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/deduct.pass.cpp @@ -16,6 +16,7 @@ // queue(Container, Allocator) -> queue; +#include #include #include #include @@ -141,19 +142,34 @@ int main(int, char**) using Cont = std::list; using Alloc = std::allocator; using DiffAlloc = test_allocator; + using Iter = int*; - struct BadAlloc {}; - using AllocAsCont = Alloc; + struct NotIter{}; + struct NotAlloc {}; - // (cont, alloc) - // - // Cannot deduce from (ALLOC_as_cont, alloc) - static_assert(SFINAEs_away); - // Cannot deduce from (cont, BAD_alloc) - static_assert(SFINAEs_away); - // Cannot deduce from (cont, DIFFERENT_alloc) + static_assert(SFINAEs_away); + static_assert(SFINAEs_away); static_assert(SFINAEs_away); + static_assert(SFINAEs_away); +#if TEST_STD_VER > 20 + static_assert(SFINAEs_away); + static_assert(SFINAEs_away); +#endif } - +#if TEST_STD_VER > 20 + { + typedef short T; + typedef test_allocator Alloc; + std::list a; + { + std::queue q(a.begin(), a.end()); + static_assert(std::is_same_v>); + } + { + std::queue q(a.begin(), a.end(), Alloc()); + static_assert(std::is_same_v>>); + } + } +#endif return 0; } diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_iterators.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_iterators.pass.cpp new file mode 100644 index 000000000000..74a59d70a513 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_iterators.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// + +// template +// stack(InputIterator, InputIterator, Allocator); + +#include +#include + +#include "test_allocator.h" + +using base_type = std::stack>>; + +class GetAlloc : public base_type { + test_allocator_statistics* stats; + +public: + GetAlloc(test_allocator_statistics& stats_, const int* begin, const int* end) + : base_type(begin, end, test_allocator(&stats_)), stats(&stats_) {} + void check() { + assert(size() == 4); + assert(stats->alloc_count > 0); + } +}; + +int main(int, char**) { + const int a[] = {4, 3, 2, 1}; + test_allocator_statistics stats{}; + GetAlloc stack(stats, a, a + 4); + assert(stack.top() == 1); + stack.pop(); + assert(stack.top() == 2); + stack.pop(); + assert(stack.top() == 3); + stack.pop(); + assert(stack.top() == 4); + stack.pop(); + assert(stack.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_iterators.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_iterators.pass.cpp new file mode 100644 index 000000000000..679e5836d5af --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_iterators.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// + +// template +// stack(InputIterator, InputIterator); + +#include +#include + +#include "test_allocator.h" + +static_assert(!std::is_constructible_v, int, int, std::allocator>); +static_assert(!std::is_constructible_v, int*, int*, int>); +static_assert( std::is_constructible_v>>, int*, int*, test_allocator>); +static_assert(!std::is_constructible_v>>, int*, int*, std::allocator>); + +struct alloc : test_allocator { + alloc(test_allocator_statistics* a); +}; +static_assert( std::is_constructible_v>, int*, int*, test_allocator_statistics*>); + +int main(int, char**) { + const int a[] = {4, 3, 2, 1}; + std::stack stack(a, a + 4); + assert(stack.top() == 1); + stack.pop(); + assert(stack.top() == 2); + stack.pop(); + assert(stack.top() == 3); + stack.pop(); + assert(stack.top() == 4); + stack.pop(); + assert(stack.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.pass.cpp index 0e6bed76b520..ad02a3ef5f55 100644 --- a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.pass.cpp @@ -16,6 +16,7 @@ // stack(Container, Allocator) -> stack; +#include #include #include #include @@ -145,19 +146,36 @@ int main(int, char**) using Cont = std::list; using Alloc = std::allocator; using DiffAlloc = test_allocator; + using Iter = int; - struct BadAlloc {}; - using AllocAsCont = Alloc; + struct NotIter {}; + struct NotAlloc {}; - // (cont, alloc) - // - // Cannot deduce from (ALLOC_as_cont, alloc) - static_assert(SFINAEs_away); - // Cannot deduce from (cont, BAD_alloc) - static_assert(SFINAEs_away); - // Cannot deduce from (cont, DIFFERENT_alloc) + static_assert(SFINAEs_away); + static_assert(SFINAEs_away); static_assert(SFINAEs_away); + static_assert(SFINAEs_away); +#if TEST_STD_VER > 20 + static_assert(SFINAEs_away); + static_assert(SFINAEs_away); +#endif } +#if TEST_STD_VER > 20 + { + typedef short T; + typedef test_allocator Alloc; + std::list a; + { + std::stack s(a.begin(), a.end()); + static_assert(std::is_same_v>); + } + { + std::stack s(a.begin(), a.end(), Alloc()); + static_assert(std::is_same_v>>); + } + } +#endif + return 0; } diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/queue.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/queue.version.pass.cpp new file mode 100644 index 000000000000..94a0a6b639cc --- /dev/null +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/queue.version.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// WARNING: This test was generated by generate_feature_test_macro_components.py +// and should not be edited manually. +// +// clang-format off + +// + +// Test the feature test macros defined by + +/* Constant Value + __cpp_lib_adaptor_iterator_pair_constructor 202106L [C++2b] +*/ + +#include +#include "test_macros.h" + +#if TEST_STD_VER < 14 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER == 14 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER == 17 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER == 20 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER > 20 + +# ifndef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should be defined in c++2b" +# endif +# if __cpp_lib_adaptor_iterator_pair_constructor != 202106L +# error "__cpp_lib_adaptor_iterator_pair_constructor should have the value 202106L in c++2b" +# endif + +#endif // TEST_STD_VER > 20 + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/stack.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/stack.version.pass.cpp new file mode 100644 index 000000000000..d1b1103bc52e --- /dev/null +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/stack.version.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// WARNING: This test was generated by generate_feature_test_macro_components.py +// and should not be edited manually. +// +// clang-format off + +// + +// Test the feature test macros defined by + +/* Constant Value + __cpp_lib_adaptor_iterator_pair_constructor 202106L [C++2b] +*/ + +#include +#include "test_macros.h" + +#if TEST_STD_VER < 14 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER == 14 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER == 17 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER == 20 + +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + +#elif TEST_STD_VER > 20 + +# ifndef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should be defined in c++2b" +# endif +# if __cpp_lib_adaptor_iterator_pair_constructor != 202106L +# error "__cpp_lib_adaptor_iterator_pair_constructor should have the value 202106L in c++2b" +# endif + +#endif // TEST_STD_VER > 20 + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp index c22dda85a247..e0f225009e41 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp @@ -16,6 +16,7 @@ // Test the feature test macros defined by /* Constant Value + __cpp_lib_adaptor_iterator_pair_constructor 202106L [C++2b] __cpp_lib_addressof_constexpr 201603L [C++17] __cpp_lib_allocate_at_least 202106L [C++2b] __cpp_lib_allocator_traits_is_always_equal 201411L [C++17] @@ -171,6 +172,10 @@ #if TEST_STD_VER < 14 +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + # ifdef __cpp_lib_addressof_constexpr # error "__cpp_lib_addressof_constexpr should not be defined before c++17" # endif @@ -749,6 +754,10 @@ #elif TEST_STD_VER == 14 +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + # ifdef __cpp_lib_addressof_constexpr # error "__cpp_lib_addressof_constexpr should not be defined before c++17" # endif @@ -1393,6 +1402,10 @@ #elif TEST_STD_VER == 17 +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + # ifndef __cpp_lib_addressof_constexpr # error "__cpp_lib_addressof_constexpr should be defined in c++17" # endif @@ -2235,6 +2248,10 @@ #elif TEST_STD_VER == 20 +# ifdef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should not be defined before c++2b" +# endif + # ifndef __cpp_lib_addressof_constexpr # error "__cpp_lib_addressof_constexpr should be defined in c++20" # endif @@ -3407,6 +3424,13 @@ #elif TEST_STD_VER > 20 +# ifndef __cpp_lib_adaptor_iterator_pair_constructor +# error "__cpp_lib_adaptor_iterator_pair_constructor should be defined in c++2b" +# endif +# if __cpp_lib_adaptor_iterator_pair_constructor != 202106L +# error "__cpp_lib_adaptor_iterator_pair_constructor should have the value 202106L in c++2b" +# endif + # ifndef __cpp_lib_addressof_constexpr # error "__cpp_lib_addressof_constexpr should be defined in c++2b" # endif diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py index 92de7b3b1284..0d43c74a6979 100755 --- a/libcxx/utils/generate_feature_test_macro_components.py +++ b/libcxx/utils/generate_feature_test_macro_components.py @@ -63,6 +63,10 @@ def add_version_header(tc): # ================ ============================================================ feature_test_macros = [ add_version_header(x) for x in [ { + "name": "__cpp_lib_adaptor_iterator_pair_constructor", + "values": { "c++2b": 202106 }, + "headers": ["queue", "stack"], + }, { "name": "__cpp_lib_addressof_constexpr", "values": { "c++17": 201603 }, "headers": ["memory"],