summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2018-05-20 14:05:31 +0000
committerMarshall Clow <mclow.lists@gmail.com>2018-05-20 14:05:31 +0000
commitd4c79d0bbb317efafa2fbede0b49c07cecb21a4d (patch)
treee98ce310b40d8564eddb0e0d442c79c912ddd281 /test
parentfa3202c56513cd0c998a548ef37c478ccc1246aa (diff)
downloadexternal_libcxx-d4c79d0bbb317efafa2fbede0b49c07cecb21a4d.tar.gz
external_libcxx-d4c79d0bbb317efafa2fbede0b49c07cecb21a4d.tar.bz2
external_libcxx-d4c79d0bbb317efafa2fbede0b49c07cecb21a4d.zip
Deduction guides for list
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@332818 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/std/containers/sequences/list/list.cons/deduct.fail.cpp42
-rw-r--r--test/std/containers/sequences/list/list.cons/deduct.pass.cpp103
2 files changed, 145 insertions, 0 deletions
diff --git a/test/std/containers/sequences/list/list.cons/deduct.fail.cpp b/test/std/containers/sequences/list/list.cons/deduct.fail.cpp
new file mode 100644
index 000000000..c3709b795
--- /dev/null
+++ b/test/std/containers/sequences/list/list.cons/deduct.fail.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+// 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>>
+// list(InputIterator, InputIterator, Allocator = Allocator())
+// -> list<typename iterator_traits<InputIterator>::value_type, Allocator>;
+//
+
+
+#include <list>
+#include <iterator>
+#include <cassert>
+#include <cstddef>
+#include <climits> // INT_MAX
+
+struct A {};
+
+int main()
+{
+// Test the explicit deduction guides
+
+// Test the implicit deduction guides
+ {
+// list (allocator &)
+ std::list lst((std::allocator<int>())); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'list'}}
+// 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
+// deque<allocator<int>, allocator<allocator<int>>>
+ }
+
+}
diff --git a/test/std/containers/sequences/list/list.cons/deduct.pass.cpp b/test/std/containers/sequences/list/list.cons/deduct.pass.cpp
new file mode 100644
index 000000000..66aa37acc
--- /dev/null
+++ b/test/std/containers/sequences/list/list.cons/deduct.pass.cpp
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+// 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>>
+// list(InputIterator, InputIterator, Allocator = Allocator())
+// -> list<typename iterator_traits<InputIterator>::value_type, Allocator>;
+//
+
+
+#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
+ {
+ const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ std::list lst(std::begin(arr), std::end(arr));
+
+ static_assert(std::is_same_v<decltype(lst), std::list<int>>, "");
+ assert(std::equal(lst.begin(), lst.end(), std::begin(arr), std::end(arr)));
+ }
+
+ {
+ const long arr[] = {INT_MAX, 1L, 2L, 3L };
+ std::list lst(std::begin(arr), std::end(arr), std::allocator<long>());
+ static_assert(std::is_same_v<decltype(lst)::value_type, long>, "");
+ assert(lst.size() == 4);
+ auto it = lst.begin();
+ assert(*it++ == INT_MAX);
+ assert(*it++ == 1L);
+ assert(*it++ == 2L);
+ }
+
+// Test the implicit deduction guides
+
+ {
+// We don't expect this one to work.
+// std::list lst(std::allocator<int>()); // list (allocator &)
+ }
+
+ {
+ std::list lst(1, A{}); // list (size_type, T)
+ static_assert(std::is_same_v<decltype(lst)::value_type, A>, "");
+ static_assert(std::is_same_v<decltype(lst)::allocator_type, std::allocator<A>>, "");
+ assert(lst.size() == 1);
+ }
+
+ {
+ std::list lst(1, A{}, test_allocator<A>()); // list (size_type, T, allocator)
+ static_assert(std::is_same_v<decltype(lst)::value_type, A>, "");
+ static_assert(std::is_same_v<decltype(lst)::allocator_type, test_allocator<A>>, "");
+ assert(lst.size() == 1);
+ }
+
+ {
+ std::list lst{1U, 2U, 3U, 4U, 5U}; // list(initializer-list)
+ static_assert(std::is_same_v<decltype(lst)::value_type, unsigned>, "");
+ assert(lst.size() == 5);
+ auto it = lst.begin();
+ std::advance(it, 2);
+ assert(*it == 3U);
+ }
+
+ {
+ std::list lst({1.0, 2.0, 3.0, 4.0}, test_allocator<double>()); // list(initializer-list, allocator)
+ static_assert(std::is_same_v<decltype(lst)::value_type, double>, "");
+ static_assert(std::is_same_v<decltype(lst)::allocator_type, test_allocator<double>>, "");
+ assert(lst.size() == 4);
+ auto it = lst.begin();
+ std::advance(it, 3);
+ assert(*it == 4.0);
+ }
+
+ {
+ std::list<long double> source;
+ std::list lst(source); // list(list &)
+ static_assert(std::is_same_v<decltype(lst)::value_type, long double>, "");
+ static_assert(std::is_same_v<decltype(lst)::allocator_type, std::allocator<long double>>, "");
+ assert(lst.size() == 0);
+ }
+}