llvm-project
105 строк · 5.0 Кб
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14
10
11// <map>
12
13// template<class InputIterator,
14// class Compare = less<iter-value-type<InputIterator>>,
15// class Allocator = allocator<iter-value-type<InputIterator>>>
16// multimap(InputIterator, InputIterator,
17// Compare = Compare(), Allocator = Allocator())
18// -> multimap<iter-value-type<InputIterator>, Compare, Allocator>;
19// template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
20// multimap(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
21// -> multimap<Key, Compare, Allocator>;
22// template<class InputIterator, class Allocator>
23// multimap(InputIterator, InputIterator, Allocator)
24// -> multimap<iter-value-type<InputIterator>, less<iter-value-type<InputIterator>>, Allocator>;
25// template<class Key, class Allocator>
26// multimap(initializer_list<Key>, Allocator)
27// -> multimap<Key, less<Key>, Allocator>;
28
29#include <climits> // INT_MAX30#include <functional>31#include <map>32#include <type_traits>33
34struct NotAnAllocator {35friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }36};37
38using P = std::pair<int, long>;39using PC = std::pair<const int, long>;40
41int main(int, char**)42{
43{44// cannot deduce Key and T from nothing45std::multimap m; // expected-error-re{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}46}47{48// cannot deduce Key and T from just (Compare)49std::multimap m(std::less<int>{});50// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}51}52{53// cannot deduce Key and T from just (Compare, Allocator)54std::multimap m(std::less<int>{}, std::allocator<PC>{});55// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}56}57{58// cannot deduce Key and T from just (Allocator)59std::multimap m(std::allocator<PC>{});60// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}61}62{63// refuse to rebind the allocator if Allocator::value_type is not exactly what we expect64const P arr[] = { {1,1L}, {2,2L}, {3,3L} };65std::multimap m(arr, arr + 3, std::allocator<P>());66// expected-error-re@map:* {{static assertion failed{{( due to requirement '.*')?}}{{.*}}Allocator::value_type must be same type as value_type}}67}68{69// cannot convert from some arbitrary unrelated type70NotAnAllocator a;71std::multimap m(a); // expected-error-re{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}72}73{74// cannot deduce that the inner braced things should be std::pair and not something else75std::multimap m{ {1,1L}, {2,2L}, {3,3L} };76// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}77}78{79// cannot deduce that the inner braced things should be std::pair and not something else80std::multimap m({ {1,1L}, {2,2L}, {3,3L} }, std::less<int>());81// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}82}83{84// cannot deduce that the inner braced things should be std::pair and not something else85std::multimap m({ {1,1L}, {2,2L}, {3,3L} }, std::less<int>(), std::allocator<PC>());86// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}87}88{89// cannot deduce that the inner braced things should be std::pair and not something else90std::multimap m({ {1,1L}, {2,2L}, {3,3L} }, std::allocator<PC>());91// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}92}93{94// since we have parens, not braces, this deliberately does not find the initializer_list constructor95std::multimap m(P{1,1L});96// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}97}98{99// since we have parens, not braces, this deliberately does not find the initializer_list constructor100std::multimap m(PC{1,1L});101// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}multimap'}}102}103
104return 0;105}
106