diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst --- a/libcxx/docs/FeatureTestMacroTable.rst +++ b/libcxx/docs/FeatureTestMacroTable.rst @@ -294,6 +294,8 @@ ------------------------------------------------- ----------------- **C++ 2b** ------------------------------------------------------------------- + ``__cpp_lib_adaptor_iterator_pair_constructor`` ``202106L`` + ------------------------------------------------- ----------------- ``__cpp_lib_byteswap`` ``202110L`` ------------------------------------------------- ----------------- ``__cpp_lib_is_scoped_enum`` ``202011L`` diff --git a/libcxx/docs/Status/Cxx2bPapers.csv b/libcxx/docs/Status/Cxx2bPapers.csv --- 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 --- a/libcxx/include/queue +++ b/libcxx/include/queue @@ -41,6 +41,8 @@ explicit queue(const container_type& c); explicit queue(container_type&& c) + template + queue(InputIterator first, InputIterator last, const Alloc&); // since C++23 template explicit queue(const Alloc& a); template @@ -51,6 +53,8 @@ queue(const queue& q, const Alloc& a); template queue(queue&& q, const Alloc& a); + template + queue(InputIterator first, InputIterator last); // since C++23 bool empty() const; size_type size() const; @@ -270,6 +274,15 @@ {c = _VSTD::move(__q.c); return *this;} #endif // _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 20 + template + _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} + + template + _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc) + : c(__first, __second, __alloc) {} +#endif + _LIBCPP_INLINE_VISIBILITY explicit queue(const container_type& __c) : c(__c) {} #ifndef _LIBCPP_CXX03_LANG @@ -358,7 +371,7 @@ operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); }; -#if _LIBCPP_STD_VER >= 17 +#if _LIBCPP_STD_VER > 14 template::value> > @@ -374,6 +387,15 @@ -> queue; #endif +#if _LIBCPP_STD_VER > 20 +template +queue(_InputIterator, _InputIterator) -> queue<__iter_value_type<_InputIterator>>; + +template +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 --- a/libcxx/include/stack +++ b/libcxx/include/stack @@ -41,11 +41,15 @@ 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; @@ -183,6 +187,15 @@ : c(_VSTD::move(__s.c), __a) {} #endif // _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 20 + template + _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last) : c{__first, __last} {} + + template + _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 @@ -231,7 +244,7 @@ operator< (const stack& __x, const stack& __y); }; -#if _LIBCPP_STD_VER >= 17 +#if _LIBCPP_STD_VER > 14 template::value> > @@ -247,6 +260,15 @@ -> stack; #endif +#if _LIBCPP_STD_VER > 20 +template +stack(_InputIterator, _InputIterator) -> stack<__iter_value_type<_InputIterator>>; + +template +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 --- 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_allocator_traits_is_always_equal 201411L @@ -345,6 +346,7 @@ #endif #if _LIBCPP_STD_VER > 20 +# define __cpp_lib_adaptor_iterator_pair_constructor 202106L # define __cpp_lib_byteswap 202110L # define __cpp_lib_is_scoped_enum 202011L // # define __cpp_lib_stacktrace 202011L 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 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_iterators.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +#include "test_allocator.h" + +using base_type = std::queue>>; +using iter = std::array::const_iterator; + +class GetAlloc : base_type { + test_allocator_statistics* stats; + +public: + GetAlloc(test_allocator_statistics& stats_, iter begin, iter 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 auto a = std::array{4, 3, 2, 1}; + test_allocator_statistics stats{}; + const auto queue = GetAlloc{stats, a.begin(), a.end()}; +} 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 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_iterators.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +int main(int, char**) { + const auto a = std::array{4, 3, 2, 1}; + const auto queue = std::queue{a.begin(), a.end()}; + assert(queue.front() == 4); + assert(queue.back() == 1); + assert(queue.size() == 4); +} 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 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_iterators.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +#include "test_allocator.h" + +using base_type = std::stack>>; +using iter = std::array::const_iterator; + +class GetAlloc : base_type { + test_allocator_statistics* stats; + +public: + GetAlloc(test_allocator_statistics& stats_, iter begin, iter 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 auto a = std::array{4, 3, 2, 1}; + test_allocator_statistics stats{}; + const auto queue = GetAlloc{stats, a.begin(), a.end()}; +} 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 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_iterators.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +int main(int, char**) { + const auto a = std::array{4, 3, 2, 1}; + const auto queue = std::stack{a.begin(), a.end()}; + assert(queue.top() == 1); + assert(queue.size() == 4); +} 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 --- /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 --- /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 --- 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_allocator_traits_is_always_equal 201411L [C++17] __cpp_lib_any 201606L [C++17] @@ -160,6 +161,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 @@ -694,6 +699,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 @@ -1294,6 +1303,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 @@ -2092,6 +2105,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 @@ -3217,6 +3234,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 --- a/libcxx/utils/generate_feature_test_macro_components.py +++ b/libcxx/utils/generate_feature_test_macro_components.py @@ -63,6 +63,10 @@ # ================ ============================================================ 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"],