diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2018-05-22 01:57:53 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2018-05-22 01:57:53 +0000 |
commit | 5b8b8b5dce587f1e5a4a31cc24f09b18bd53ff9a (patch) | |
tree | 8f04be8d8eaf76d4e17086a1c1d3993a4beab9fa /libcxx/test/std/containers/container.adaptors/stack | |
parent | 2d3eaeb2d485c464d493db9d301a2dd7e9d8d57c (diff) | |
download | bcm5719-llvm-5b8b8b5dce587f1e5a4a31cc24f09b18bd53ff9a.tar.gz bcm5719-llvm-5b8b8b5dce587f1e5a4a31cc24f09b18bd53ff9a.zip |
Deduction guides for the container adaptors - queue, stack, and priority_queue
llvm-svn: 332927
Diffstat (limited to 'libcxx/test/std/containers/container.adaptors/stack')
-rw-r--r-- | libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.fail.cpp | 53 | ||||
-rw-r--r-- | libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.pass.cpp | 91 |
2 files changed, 144 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.fail.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.fail.cpp new file mode 100644 index 00000000000..e14965adadc --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.fail.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + + +// template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> +// vector(InputIterator, InputIterator, Allocator = Allocator()) +// -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; +// + + +#include <stack> +#include <list> +#include <iterator> +#include <cassert> +#include <cstddef> + + +int main() +{ +// Test the explicit deduction guides + { +// stack(const Container&, const Alloc&); +// The '45' is not an allocator + std::stack stk(std::list<int>({1,2,3}), 45); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'stack'}} + } + + { +// stack(const stack&, const Alloc&); +// The '45' is not an allocator + std::stack<int> source; + std::stack stk(source, 45); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'stack'}} + } + +// Test the implicit deduction guides + { +// stack (allocator &) + std::stack stk((std::allocator<int>())); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'stack'}} +// Note: The extra parens are necessary, since otherwise clang decides it is a function declaration. +// Also, we can't use {} instead of parens, because that constructs a +// stack<allocator<int>, allocator<allocator<int>>> + } + +} 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 new file mode 100644 index 00000000000..4ae11376b2b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/deduct.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + + +// template<class Container> +// stack(Container) -> stack<typename Container::value_type, Container>; +// +// template<class Container, class Allocator> +// stack(Container, Allocator) -> stack<typename Container::value_type, Container>; + + +#include <stack> +#include <vector> +#include <list> +#include <iterator> +#include <cassert> +#include <cstddef> +#include <climits> // INT_MAX + +#include "test_macros.h" +#include "test_iterators.h" +#include "test_allocator.h" + +struct A {}; + +int main() +{ + +// Test the explicit deduction guides + { + std::vector<int> v{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::stack stk(v); + + static_assert(std::is_same_v<decltype(stk), std::stack<int, std::vector<int>>>, ""); + assert(stk.size() == v.size()); + assert(stk.top() == v.back()); + } + + { + std::list<long, test_allocator<long>> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + std::stack stk(l, test_allocator<long>(0,2)); // different allocator + static_assert(std::is_same_v<decltype(stk)::container_type, std::list<long, test_allocator<long>>>, ""); + static_assert(std::is_same_v<decltype(stk)::value_type, long>, ""); + 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<int>()); // stack (allocator &) + } + + { + std::stack<A> source; + std::stack stk(source); // stack(stack &) + static_assert(std::is_same_v<decltype(stk)::value_type, A>, ""); + static_assert(std::is_same_v<decltype(stk)::container_type, std::deque<A>>, ""); + assert(stk.size() == 0); + } + + { +// This one is odd - you can pass an allocator in to use, but the allocator +// has to match the type of the one used by the underlying container + typedef short T; + typedef test_allocator<T> A; + typedef std::deque<T, A> C; + + C c{0,1,2,3}; + std::stack<T, C> source(c); + std::stack stk(source, A(2)); // stack(stack &, allocator) + static_assert(std::is_same_v<decltype(stk)::value_type, T>, ""); + static_assert(std::is_same_v<decltype(stk)::container_type, C>, ""); + assert(stk.size() == 4); + assert(stk.top() == 3); + } + +} |