//===----------------------------------------------------------------------===// // // 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 // UNSUPPORTED: clang-5, apple-clang-9 // UNSUPPORTED: libcpp-no-deduction-guides // Clang 5 will generate bad implicit deduction guides // Specifically, for the copy constructor. // template // stack(Container) -> stack; // // template // stack(Container, Allocator) -> stack; #include #include #include #include #include #include #include #include // INT_MAX #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>); } } return 0; }