Index: include/set =================================================================== --- include/set +++ include/set @@ -836,6 +836,34 @@ #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template::value_type>, + class _Allocator = allocator::value_type>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if::value, void>::type> +set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) + -> set::value_type, _Compare, _Allocator>; + +template, + class _Allocator = allocator<_Key>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if::value, void>::type> +set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) + -> set<_Key, _Compare, _Allocator>; + +template::value, void>::type> +set(_InputIterator, _InputIterator, _Allocator) + -> set::value_type, + less::value_type>, _Allocator>; + +template::value, void>::type> +set(initializer_list<_Key>, _Allocator) + -> set<_Key, less<_Key>, _Allocator>; +#endif + #ifndef _LIBCPP_CXX03_LANG template @@ -1324,6 +1352,34 @@ #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template::value_type>, + class _Allocator = allocator::value_type>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if::value, void>::type> +multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) + -> multiset::value_type, _Compare, _Allocator>; + +template, + class _Allocator = allocator<_Key>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if::value, void>::type> +multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) + -> multiset<_Key, _Compare, _Allocator>; + +template::value, void>::type> +multiset(_InputIterator, _InputIterator, _Allocator) + -> multiset::value_type, + less::value_type>, _Allocator>; + +template::value, void>::type> +multiset(initializer_list<_Key>, _Allocator) + -> multiset<_Key, less<_Key>, _Allocator>; +#endif + #ifndef _LIBCPP_CXX03_LANG template Index: test/std/containers/associative/multiset/multiset.cons/deduct.fail.cpp =================================================================== --- /dev/null +++ test/std/containers/associative/multiset/multiset.cons/deduct.fail.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// template>, +// class Allocator = allocator>> +// multiset(InputIterator, InputIterator, +// Compare = Compare(), Allocator = Allocator()) +// -> multiset, Compare, Allocator>; +// template, class Allocator = allocator> +// multiset(initializer_list, Compare = Compare(), Allocator = Allocator()) +// -> multiset; +// template +// multiset(InputIterator, InputIterator, Allocator) +// -> multiset, less>, Allocator>; +// template +// multiset(initializer_list, Allocator) -> multiset, Allocator>; + +#include +#include + +struct A {}; + +int main(int, char**) +{ + { + A a; + std::multiset s(a); // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}} + } + { + std::allocator a; + std::multiset s(a); // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'multiset'}} + } + + return 0; +} Index: test/std/containers/associative/multiset/multiset.cons/deduct.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/associative/multiset/multiset.cons/deduct.pass.cpp @@ -0,0 +1,164 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// template>, +// class Allocator = allocator>> +// multiset(InputIterator, InputIterator, +// Compare = Compare(), Allocator = Allocator()) +// -> multiset, Compare, Allocator>; +// template, class Allocator = allocator> +// multiset(initializer_list, Compare = Compare(), Allocator = Allocator()) +// -> multiset; +// template +// multiset(InputIterator, InputIterator, Allocator) +// -> multiset, less>, Allocator>; +// template +// multiset(initializer_list, Allocator) -> multiset, Allocator>; + +#include +#include +#include // INT_MAX + +#include "test_allocator.h" + +struct A { + friend bool operator<(A, A) { return false; } +}; + +int main(int, char**) +{ + +// Test the explicit deduction guides + { + const int arr[] = { 1, 2, 1, INT_MAX, 3 }; + std::multiset s(std::begin(arr), std::end(arr)); + + static_assert(std::is_same_v>, ""); + 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()); + + static_assert(std::is_same_v>>, ""); + 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(), test_allocator(0, 42)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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 s{ 1, 2, 1, INT_MAX, 3 }; + + static_assert(std::is_same_v>, ""); + 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()); + + static_assert(std::is_same_v>>, ""); + 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(), test_allocator(0, 43)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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(0, 44)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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(0, 45)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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); + } + + { + std::multiset source; + std::multiset s(source); // multiset(multiset &) + static_assert(std::is_same_v>, ""); + assert(s.size() == 0); + } + + { + std::multiset source; + std::multiset s{source}; // multiset(multiset &) + static_assert(std::is_same_v>, ""); + assert(s.size() == 0); + } + + { + A a; + std::multiset s{a}; // multiset(initializer_list) + static_assert(std::is_same_v>, ""); + assert(s.size() == 1); + } + + { + std::multiset source; + std::multiset s{source, source}; // multiset(initializer_list>) + static_assert(std::is_same_v>>, ""); + assert(s.size() == 1); + } + + { + A a; + std::multiset s{a, a}; // multiset(initializer_list) + static_assert(std::is_same_v>, ""); + assert(s.size() == 1); + } + + { + int source[3] = {3, 4, 5}; + std::multiset s(source, source + 3); // multiset(InputIterator, InputIterator) + static_assert(std::is_same_v>, ""); + assert(s.size() == 3); + } + + { + int source[3] = {3, 4, 5}; + std::multiset s{source, source + 3}; // multiset(initializer_list) + static_assert(std::is_same_v>, ""); + assert(s.size() == 2); + } + + return 0; +} Index: test/std/containers/associative/set/set.cons/deduct.fail.cpp =================================================================== --- /dev/null +++ test/std/containers/associative/set/set.cons/deduct.fail.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// template>, +// class Allocator = allocator>> +// set(InputIterator, InputIterator, +// Compare = Compare(), Allocator = Allocator()) +// -> set, Compare, Allocator>; +// template, class Allocator = allocator> +// set(initializer_list, Compare = Compare(), Allocator = Allocator()) +// -> set; +// template +// set(InputIterator, InputIterator, Allocator) +// -> set, less>, Allocator>; +// template +// set(initializer_list, Allocator) -> set, Allocator>; + +#include +#include + +struct A {}; + +int main(int, char**) +{ + { + A a; + std::set s(a); // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'set'}} + } + { + std::allocator a; + std::set s(a); // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'set'}} + } + + return 0; +} Index: test/std/containers/associative/set/set.cons/deduct.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/associative/set/set.cons/deduct.pass.cpp @@ -0,0 +1,164 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// template>, +// class Allocator = allocator>> +// set(InputIterator, InputIterator, +// Compare = Compare(), Allocator = Allocator()) +// -> set, Compare, Allocator>; +// template, class Allocator = allocator> +// set(initializer_list, Compare = Compare(), Allocator = Allocator()) +// -> set; +// template +// set(InputIterator, InputIterator, Allocator) +// -> set, less>, Allocator>; +// template +// set(initializer_list, Allocator) -> set, Allocator>; + +#include +#include +#include // INT_MAX + +#include "test_allocator.h" + +struct A { + friend bool operator<(A, A) { return false; } +}; + +int main(int, char**) +{ + +// Test the explicit deduction guides + { + const int arr[] = { 1, 2, 1, INT_MAX, 3 }; + std::set s(std::begin(arr), std::end(arr)); + + static_assert(std::is_same_v>, ""); + 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()); + + static_assert(std::is_same_v>>, ""); + 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(), test_allocator(0, 42)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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 s{ 1, 2, 1, INT_MAX, 3 }; + + static_assert(std::is_same_v>, ""); + 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()); + + static_assert(std::is_same_v>>, ""); + 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(), test_allocator(0, 43)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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(0, 44)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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(0, 45)); + + static_assert(std::is_same_v, test_allocator>>, ""); + 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); + } + + { + std::set source; + std::set s(source); // set(set &) + static_assert(std::is_same_v>, ""); + assert(s.size() == 0); + } + + { + std::set source; + std::set s{source}; // set(set &) + static_assert(std::is_same_v>, ""); + assert(s.size() == 0); + } + + { + A a; + std::set s{a}; // set(initializer_list) + static_assert(std::is_same_v>, ""); + assert(s.size() == 1); + } + + { + std::set source; + std::set s{source, source}; // set(initializer_list>) + static_assert(std::is_same_v>>, ""); + assert(s.size() == 1); + } + + { + A a; + std::set s{a, a}; // set(initializer_list) + static_assert(std::is_same_v>, ""); + assert(s.size() == 1); + } + + { + int source[3] = {3, 4, 5}; + std::set s(source, source + 3); // set(InputIterator, InputIterator) + static_assert(std::is_same_v>, ""); + assert(s.size() == 3); + } + + { + int source[3] = {3, 4, 5}; + std::set s{source, source + 3}; // set(initializer_list) + static_assert(std::is_same_v>, ""); + assert(s.size() == 2); + } + + return 0; +}