//===----------------------------------------------------------------------===// // // 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 // template // stack(Container) -> stack; // // template // stack(Container, Allocator) -> stack; // // template // stack(from_range_t, R&&) -> stack>; // since C++23 // // template // stack(from_range_t, R&&, Allocator) // -> stack, deque, Allocator>>; // since C++23 #include #include #include #include #include #include #include #include #include // INT_MAX #include "deduction_guides_sfinae_checks.h" #include "test_macros.h" #include "test_iterators.h" #include "test_allocator.h" struct A {}; int main(int, char**) { // Test the explicit deduction guides { std::vector v{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::stack stk(v); static_assert(std::is_same_v>>, ""); assert(stk.size() == v.size()); assert(stk.top() == v.back()); } { std::list> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; std::stack stk(l, test_allocator(0,2)); // different allocator static_assert(std::is_same_v>>, ""); static_assert(std::is_same_v, ""); assert(stk.size() == 10); assert(stk.top() == 19); // I'd like to assert that we've gotten the right allocator in the stack, but // I don't know how to get at the underlying container. } // Test the implicit deduction guides { // We don't expect this one to work - no way to implicitly get value_type // std::stack stk(std::allocator()); // stack (allocator &) } { std::stack source; std::stack stk(source); // stack(stack &) static_assert(std::is_same_v, ""); static_assert(std::is_same_v>, ""); assert(stk.size() == 0); } { typedef short T; typedef test_allocator Alloc; typedef std::list Cont; typedef test_allocator ConvertibleToAlloc; static_assert(std::uses_allocator_v && !std::is_same_v); { Cont cont; std::stack stk(cont, Alloc(2)); static_assert(std::is_same_v>); } { Cont cont; std::stack stk(cont, ConvertibleToAlloc(2)); static_assert(std::is_same_v>); } { Cont cont; std::stack stk(std::move(cont), Alloc(2)); static_assert(std::is_same_v>); } { Cont cont; std::stack stk(std::move(cont), ConvertibleToAlloc(2)); static_assert(std::is_same_v>); } } { typedef short T; typedef test_allocator Alloc; typedef std::list Cont; typedef test_allocator ConvertibleToAlloc; static_assert(std::uses_allocator_v && !std::is_same_v); { std::stack source; std::stack stk(source, Alloc(2)); static_assert(std::is_same_v>); } { std::stack source; std::stack stk(source, ConvertibleToAlloc(2)); static_assert(std::is_same_v>); } { std::stack source; std::stack stk(std::move(source), Alloc(2)); static_assert(std::is_same_v>); } { std::stack source; std::stack stk(std::move(source), ConvertibleToAlloc(2)); static_assert(std::is_same_v>); } } #if TEST_STD_VER >= 23 { 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>>); } } { { std::stack c(std::from_range, std::array()); static_assert(std::is_same_v>); } { using Alloc = test_allocator; std::stack c(std::from_range, std::array(), Alloc()); static_assert(std::is_same_v>>); } } #endif ContainerAdaptorDeductionGuidesSfinaeAway>(); return 0; }