53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_map>12 13// Test CTAD on cases where deduction should fail.14 15#include <flat_map>16#include <functional>17#include <memory>18#include <utility>19#include <vector>20 21struct NotAnAllocator {22 friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }23};24 25using P = std::pair<int, long>;26using PC = std::pair<const int, long>;27 28template <class... Args>29concept CanDeductFlatMap = requires { std::flat_map{std::declval<Args>()...}; };30 31static_assert(CanDeductFlatMap<std::vector<int>, std::vector<int>>);32 33// cannot deduce Key and T from nothing34static_assert(!CanDeductFlatMap<>);35 36// cannot deduce Key and T from just (KeyContainer), even if it's a container of pairs37static_assert(!CanDeductFlatMap<std::vector<std::pair<int, int>>>);38 39// cannot deduce Key and T from just (KeyContainer, Allocator)40static_assert(!CanDeductFlatMap<std::vector<int>, std::allocator<std::pair<const int, int>>>);41 42// cannot deduce Key and T from just (Compare)43static_assert(!CanDeductFlatMap<std::less<int>>);44 45// cannot deduce Key and T from just (Compare, Allocator)46static_assert(!CanDeductFlatMap<std::less<int>, std::allocator<PC>>);47 48// cannot deduce Key and T from just (Allocator)49static_assert(!CanDeductFlatMap<std::allocator<PC>>);50 51// cannot convert from some arbitrary unrelated type52static_assert(!CanDeductFlatMap<NotAnAllocator>);53