summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers/associative
diff options
context:
space:
mode:
authorLouis Dionne <ldionne@apple.com>2019-06-11 18:21:08 +0000
committerLouis Dionne <ldionne@apple.com>2019-06-11 18:21:08 +0000
commite20865c387e09ea0ebd5add15c762cd5271ff65f (patch)
tree87618c3a92d62133c9c649e58db0690cdd0a5f4c /libcxx/test/std/containers/associative
parent9970817c57f7fe03cb75c8a37a11b5d7d1fbeb6f (diff)
downloadbcm5719-llvm-e20865c387e09ea0ebd5add15c762cd5271ff65f.tar.gz
bcm5719-llvm-e20865c387e09ea0ebd5add15c762cd5271ff65f.zip
[libc++] Implement deduction guides for <set>
This is part of C++17's P0433. Thanks to Arthur O'Dwyer for the patch. Differential Revision: https://reviews.llvm.org/D58582 llvm-svn: 363090
Diffstat (limited to 'libcxx/test/std/containers/associative')
-rw-r--r--libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.fail.cpp69
-rw-r--r--libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.pass.cpp190
-rw-r--r--libcxx/test/std/containers/associative/set/set.cons/deduct.fail.cpp69
-rw-r--r--libcxx/test/std/containers/associative/set/set.cons/deduct.pass.cpp188
4 files changed, 516 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.fail.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.fail.cpp
new file mode 100644
index 00000000000..3b5b0db3a5b
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.fail.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// UNSUPPORTED: libcpp-no-deduction-guides
+
+// template<class InputIterator,
+// class Compare = less<iter-value-type<InputIterator>>,
+// class Allocator = allocator<iter-value-type<InputIterator>>>
+// multiset(InputIterator, InputIterator,
+// Compare = Compare(), Allocator = Allocator())
+// -> multiset<iter-value-type<InputIterator>, Compare, Allocator>;
+// template<class Key, class Compare = less<Key>,
+// class Allocator = allocator<Key>>
+// multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
+// -> multiset<Key, Compare, Allocator>;
+// template<class InputIterator, class Allocator>
+// multiset(InputIterator, InputIterator, Allocator)
+// -> multiset<iter-value-type<InputIterator>,
+// less<iter-value-type<InputIterator>>, Allocator>;
+// template<class Key, class Allocator>
+// multiset(initializer_list<Key>, Allocator)
+// -> multiset<Key, less<Key>, Allocator>;
+
+#include <functional>
+#include <set>
+#include <type_traits>
+
+struct NotAnAllocator {
+ friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
+};
+
+int main(int, char **) {
+ {
+ // cannot deduce Key from nothing
+ std::multiset s;
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}}
+ }
+ {
+ // cannot deduce Key from just (Compare)
+ std::multiset s(std::less<int>{});
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}}
+ }
+ {
+ // cannot deduce Key from just (Compare, Allocator)
+ std::multiset s(std::less<int>{}, std::allocator<int>{});
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}}
+ }
+ {
+ // cannot deduce Key from multiset(Allocator)
+ std::multiset s(std::allocator<int>{});
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}}
+ }
+ {
+ // since we have parens, not braces, this deliberately does not find the
+ // initializer_list constructor
+ NotAnAllocator a;
+ std::multiset s(a);
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}}
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.pass.cpp
new file mode 100644
index 00000000000..22db3df3bcd
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/deduct.pass.cpp
@@ -0,0 +1,190 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// UNSUPPORTED: libcpp-no-deduction-guides
+
+// template<class InputIterator,
+// class Compare = less<iter-value-type<InputIterator>>,
+// class Allocator = allocator<iter-value-type<InputIterator>>>
+// multiset(InputIterator, InputIterator,
+// Compare = Compare(), Allocator = Allocator())
+// -> multiset<iter-value-type<InputIterator>, Compare, Allocator>;
+// template<class Key, class Compare = less<Key>,
+// class Allocator = allocator<Key>>
+// multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
+// -> multiset<Key, Compare, Allocator>;
+// template<class InputIterator, class Allocator>
+// multiset(InputIterator, InputIterator, Allocator)
+// -> multiset<iter-value-type<InputIterator>,
+// less<iter-value-type<InputIterator>>, Allocator>;
+// template<class Key, class Allocator>
+// multiset(initializer_list<Key>, Allocator)
+// -> multiset<Key, less<Key>, Allocator>;
+
+#include <algorithm> // std::equal
+#include <cassert>
+#include <climits> // INT_MAX
+#include <functional>
+#include <set>
+#include <type_traits>
+
+#include "test_allocator.h"
+
+struct NotAnAllocator {
+ friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
+};
+
+int main(int, char **) {
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::multiset s(std::begin(arr), std::end(arr));
+
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<int>);
+ const int expected_s[] = { 1, 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::multiset s(std::begin(arr), std::end(arr), std::greater<int>());
+
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<int, std::greater<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::multiset s(std::begin(arr), std::end(arr), std::greater<int>(),
+ test_allocator<int>(0, 42));
+
+ ASSERT_SAME_TYPE(
+ decltype(s),
+ std::multiset<int, std::greater<int>, test_allocator<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 42);
+ }
+
+ {
+ std::multiset<long> source;
+ std::multiset s(source);
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<long>);
+ assert(s.size() == 0);
+ }
+
+ {
+ std::multiset<long> source;
+ std::multiset s{ source }; // braces instead of parens
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<long>);
+ assert(s.size() == 0);
+ }
+
+ {
+ std::multiset<long> source;
+ std::multiset s(source, std::multiset<long>::allocator_type());
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<long>);
+ assert(s.size() == 0);
+ }
+
+ {
+ std::multiset s{ 1, 2, 1, INT_MAX, 3 };
+
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<int>);
+ const int expected_s[] = { 1, 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ std::multiset s({ 1, 2, 1, INT_MAX, 3 }, std::greater<int>());
+
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<int, std::greater<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ std::multiset s({ 1, 2, 1, INT_MAX, 3 }, std::greater<int>(),
+ test_allocator<int>(0, 43));
+
+ ASSERT_SAME_TYPE(
+ decltype(s),
+ std::multiset<int, std::greater<int>, test_allocator<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 43);
+ }
+
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::multiset s(std::begin(arr), std::end(arr), test_allocator<int>(0, 44));
+
+ ASSERT_SAME_TYPE(decltype(s),
+ std::multiset<int, std::less<int>, test_allocator<int> >);
+ const int expected_s[] = { 1, 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 44);
+ }
+
+ {
+ std::multiset s({ 1, 2, 1, INT_MAX, 3 }, test_allocator<int>(0, 45));
+
+ ASSERT_SAME_TYPE(decltype(s),
+ std::multiset<int, std::less<int>, test_allocator<int> >);
+ const int expected_s[] = { 1, 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 45);
+ }
+
+ {
+ NotAnAllocator a;
+ std::multiset s{ a }; // multiset(initializer_list<NotAnAllocator>)
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<NotAnAllocator>);
+ assert(s.size() == 1);
+ }
+
+ {
+ std::multiset<long> source;
+ std::multiset s{ source, source }; // multiset(initializer_list<multiset<long>>)
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<std::multiset<long> >);
+ assert(s.size() == 2);
+ }
+
+ {
+ NotAnAllocator a;
+ std::multiset s{ a, a }; // multiset(initializer_list<NotAnAllocator>)
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<NotAnAllocator>);
+ assert(s.size() == 2);
+ }
+
+ {
+ int source[3] = { 3, 4, 5 };
+ std::multiset s(source, source + 3); // multiset(InputIterator, InputIterator)
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<int>);
+ assert(s.size() == 3);
+ }
+
+ {
+ int source[3] = { 3, 4, 5 };
+ std::multiset s{ source, source + 3 }; // multiset(initializer_list<int*>)
+ ASSERT_SAME_TYPE(decltype(s), std::multiset<int *>);
+ assert(s.size() == 2);
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/associative/set/set.cons/deduct.fail.cpp b/libcxx/test/std/containers/associative/set/set.cons/deduct.fail.cpp
new file mode 100644
index 00000000000..861339b4f1c
--- /dev/null
+++ b/libcxx/test/std/containers/associative/set/set.cons/deduct.fail.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// UNSUPPORTED: libcpp-no-deduction-guides
+
+// template<class InputIterator,
+// class Compare = less<iter-value-type<InputIterator>>,
+// class Allocator = allocator<iter-value-type<InputIterator>>>
+// set(InputIterator, InputIterator,
+// Compare = Compare(), Allocator = Allocator())
+// -> set<iter-value-type<InputIterator>, Compare, Allocator>;
+// template<class Key, class Compare = less<Key>,
+// class Allocator = allocator<Key>>
+// set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
+// -> set<Key, Compare, Allocator>;
+// template<class InputIterator, class Allocator>
+// set(InputIterator, InputIterator, Allocator)
+// -> set<iter-value-type<InputIterator>,
+// less<iter-value-type<InputIterator>>, Allocator>;
+// template<class Key, class Allocator>
+// set(initializer_list<Key>, Allocator)
+// -> set<Key, less<Key>, Allocator>;
+
+#include <functional>
+#include <set>
+#include <type_traits>
+
+struct NotAnAllocator {
+ friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
+};
+
+int main(int, char **) {
+ {
+ // cannot deduce Key from nothing
+ std::set s;
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'set'}}
+ }
+ {
+ // cannot deduce Key from just (Compare)
+ std::set s(std::less<int>{});
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'set'}}
+ }
+ {
+ // cannot deduce Key from just (Compare, Allocator)
+ std::set s(std::less<int>{}, std::allocator<int>{});
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'set'}}
+ }
+ {
+ // cannot deduce Key from just (Allocator)
+ std::set s(std::allocator<int>{});
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'set'}}
+ }
+ {
+ // since we have parens, not braces, this deliberately does not find the
+ // initializer_list constructor
+ NotAnAllocator a;
+ std::set s(a);
+ // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'set'}}
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/associative/set/set.cons/deduct.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/deduct.pass.cpp
new file mode 100644
index 00000000000..019ca61a00a
--- /dev/null
+++ b/libcxx/test/std/containers/associative/set/set.cons/deduct.pass.cpp
@@ -0,0 +1,188 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// UNSUPPORTED: libcpp-no-deduction-guides
+
+// template<class InputIterator,
+// class Compare = less<iter-value-type<InputIterator>>,
+// class Allocator = allocator<iter-value-type<InputIterator>>>
+// set(InputIterator, InputIterator,
+// Compare = Compare(), Allocator = Allocator())
+// -> set<iter-value-type<InputIterator>, Compare, Allocator>;
+// template<class Key, class Compare = less<Key>,
+// class Allocator = allocator<Key>>
+// set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
+// -> set<Key, Compare, Allocator>;
+// template<class InputIterator, class Allocator>
+// set(InputIterator, InputIterator, Allocator)
+// -> set<iter-value-type<InputIterator>,
+// less<iter-value-type<InputIterator>>, Allocator>;
+// template<class Key, class Allocator>
+// set(initializer_list<Key>, Allocator)
+// -> set<Key, less<Key>, Allocator>;
+
+#include <algorithm> // std::equal
+#include <cassert>
+#include <climits> // INT_MAX
+#include <functional>
+#include <set>
+#include <type_traits>
+
+#include "test_allocator.h"
+
+struct NotAnAllocator {
+ friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
+};
+
+int main(int, char **) {
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::set s(std::begin(arr), std::end(arr));
+
+ ASSERT_SAME_TYPE(decltype(s), std::set<int>);
+ const int expected_s[] = { 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::set s(std::begin(arr), std::end(arr), std::greater<int>());
+
+ ASSERT_SAME_TYPE(decltype(s), std::set<int, std::greater<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::set s(std::begin(arr), std::end(arr), std::greater<int>(),
+ test_allocator<int>(0, 42));
+
+ ASSERT_SAME_TYPE(decltype(s),
+ std::set<int, std::greater<int>, test_allocator<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 42);
+ }
+
+ {
+ std::set<long> source;
+ std::set s(source);
+ ASSERT_SAME_TYPE(decltype(s), std::set<long>);
+ assert(s.size() == 0);
+ }
+
+ {
+ std::set<long> source;
+ std::set s{ source }; // braces instead of parens
+ ASSERT_SAME_TYPE(decltype(s), std::set<long>);
+ assert(s.size() == 0);
+ }
+
+ {
+ std::set<long> source;
+ std::set s(source, std::set<long>::allocator_type());
+ ASSERT_SAME_TYPE(decltype(s), std::set<long>);
+ assert(s.size() == 0);
+ }
+
+ {
+ std::set s{ 1, 2, 1, INT_MAX, 3 };
+
+ ASSERT_SAME_TYPE(decltype(s), std::set<int>);
+ const int expected_s[] = { 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ std::set s({ 1, 2, 1, INT_MAX, 3 }, std::greater<int>());
+
+ ASSERT_SAME_TYPE(decltype(s), std::set<int, std::greater<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ }
+
+ {
+ std::set s({ 1, 2, 1, INT_MAX, 3 }, std::greater<int>(),
+ test_allocator<int>(0, 43));
+
+ ASSERT_SAME_TYPE(decltype(s),
+ std::set<int, std::greater<int>, test_allocator<int> >);
+ const int expected_s[] = { INT_MAX, 3, 2, 1 };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 43);
+ }
+
+ {
+ const int arr[] = { 1, 2, 1, INT_MAX, 3 };
+ std::set s(std::begin(arr), std::end(arr), test_allocator<int>(0, 44));
+
+ ASSERT_SAME_TYPE(decltype(s),
+ std::set<int, std::less<int>, test_allocator<int> >);
+ const int expected_s[] = { 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 44);
+ }
+
+ {
+ std::set s({ 1, 2, 1, INT_MAX, 3 }, test_allocator<int>(0, 45));
+
+ ASSERT_SAME_TYPE(decltype(s),
+ std::set<int, std::less<int>, test_allocator<int> >);
+ const int expected_s[] = { 1, 2, 3, INT_MAX };
+ assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
+ std::end(expected_s)));
+ assert(s.get_allocator().get_id() == 45);
+ }
+
+ {
+ NotAnAllocator a;
+ std::set s{ a }; // set(initializer_list<NotAnAllocator>)
+ ASSERT_SAME_TYPE(decltype(s), std::set<NotAnAllocator>);
+ assert(s.size() == 1);
+ }
+
+ {
+ std::set<long> source;
+ std::set s{ source, source }; // set(initializer_list<set<long>>)
+ ASSERT_SAME_TYPE(decltype(s), std::set<std::set<long> >);
+ assert(s.size() == 1);
+ }
+
+ {
+ NotAnAllocator a;
+ std::set s{ a, a }; // set(initializer_list<NotAnAllocator>)
+ ASSERT_SAME_TYPE(decltype(s), std::set<NotAnAllocator>);
+ assert(s.size() == 1);
+ }
+
+ {
+ int source[3] = { 3, 4, 5 };
+ std::set s(source, source + 3); // set(InputIterator, InputIterator)
+ ASSERT_SAME_TYPE(decltype(s), std::set<int>);
+ assert(s.size() == 3);
+ }
+
+ {
+ int source[3] = { 3, 4, 5 };
+ std::set s{ source, source + 3 }; // set(initializer_list<int*>)
+ ASSERT_SAME_TYPE(decltype(s), std::set<int *>);
+ assert(s.size() == 2);
+ }
+
+ return 0;
+}
OpenPOWER on IntegriCloud