//===----------------------------------------------------------------------===// // // 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++98, c++03, c++11, c++14 // UNSUPPORTED: libcpp-no-deduction-guides // UNSUPPORTED: apple-clang-9.1 // template>, // class Pred = equal_to>, // class Allocator = allocator>> // unordered_set(InputIterator, InputIterator, typename see below::size_type = see below, // Hash = Hash(), Pred = Pred(), Allocator = Allocator()) // -> unordered_set, // Hash, Pred, Allocator>; // // template, // class Pred = equal_to, class Allocator = allocator> // unordered_set(initializer_list, typename see below::size_type = see below, // Hash = Hash(), Pred = Pred(), Allocator = Allocator()) // -> unordered_set; // // template // unordered_set(InputIterator, InputIterator, typename see below::size_type, Allocator) // -> unordered_set, // hash>, // equal_to>, // Allocator>; // // template // unordered_set(InputIterator, InputIterator, typename see below::size_type, // Hash, Allocator) // -> unordered_set, Hash, // equal_to>, // Allocator>; // // template // unordered_set(initializer_list, typename see below::size_type, Allocator) // -> unordered_set, equal_to, Allocator>; // // template // unordered_set(initializer_list, typename see below::size_type, Hash, Allocator) // -> unordered_set, Allocator>; #include // is_permutation #include #include // INT_MAX #include #include #include "test_allocator.h" int main(int, char**) { const int expected_s[] = {1, 2, 3, INT_MAX}; { const int arr[] = { 1, 2, 1, INT_MAX, 3 }; std::unordered_set s(std::begin(arr), std::end(arr)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { const int arr[] = { 1, 2, 1, INT_MAX, 3 }; std::unordered_set s(std::begin(arr), std::end(arr), 42); ASSERT_SAME_TYPE(decltype(s), std::unordered_set); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { const int arr[] = { 1, 2, 1, INT_MAX, 3 }; std::unordered_set s(std::begin(arr), std::end(arr), 42, std::hash()); ASSERT_SAME_TYPE(decltype(s), std::unordered_set>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { const int arr[] = { 1, 2, 1, INT_MAX, 3 }; std::unordered_set s(std::begin(arr), std::end(arr), 42, std::hash(), test_allocator(0, 40)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to, test_allocator>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); assert(s.get_allocator().get_id() == 40); } { std::unordered_set, std::equal_to<>, test_allocator> source; std::unordered_set s(source); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s.size() == 0); } { std::unordered_set, std::equal_to<>, test_allocator> source; std::unordered_set s{source}; // braces instead of parens ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s.size() == 0); } { std::unordered_set, std::equal_to<>, test_allocator> source; std::unordered_set s(source, test_allocator(0, 41)); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s.size() == 0); assert(s.get_allocator().get_id() == 41); } { std::unordered_set, std::equal_to<>, test_allocator> source; std::unordered_set s{source, test_allocator(0, 42)}; // braces instead of parens ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s.size() == 0); assert(s.get_allocator().get_id() == 42); } { std::unordered_set s{ 1, 2, 1, INT_MAX, 3 }; ASSERT_SAME_TYPE(decltype(s), std::unordered_set); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42); ASSERT_SAME_TYPE(decltype(s), std::unordered_set); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42, std::hash()); ASSERT_SAME_TYPE(decltype(s), std::unordered_set>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42, std::hash(), std::equal_to<>()); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to<>>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); } { std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42, std::hash(), std::equal_to<>(), test_allocator(0, 43)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to<>, test_allocator>); assert(std::is_permutation(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::unordered_set s(std::begin(arr), std::end(arr), 42, test_allocator(0, 44)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to, test_allocator>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); assert(s.get_allocator().get_id() == 44); } { const int arr[] = { 1, 2, 1, INT_MAX, 3 }; std::unordered_set s(std::begin(arr), std::end(arr), 42, std::hash(), test_allocator(0, 44)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to, test_allocator>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); assert(s.get_allocator().get_id() == 44); } { std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42, test_allocator(0, 43)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to, test_allocator>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); assert(s.get_allocator().get_id() == 43); } { std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42, std::hash(), test_allocator(0, 42)); ASSERT_SAME_TYPE(decltype(s), std::unordered_set, std::equal_to, test_allocator>); assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s))); assert(s.get_allocator().get_id() == 42); } return 0; }