Debian Codegraph @

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/ctad.static.compile.pass.cpp

raw
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, c++17, c++20
10
11 // checks that CTAD for std::function works properly with static operator() overloads
12
13 #include <functional>
14 #include <type_traits>
15
16 struct Except0 {
17 static void operator()() {}
18 };
19 static_assert(std::is_same_v<decltype(std::function{Except0{}}), std::function<void()>>);
20
21 struct Except1 {
22 static int operator()(int&) { return 0; }
23 };
24 static_assert(std::is_same_v<decltype(std::function{Except1{}}), std::function<int(int&)>>);
25
26 struct Except2 {
27 static int operator()(int*, long*) { return 0; }
28 };
29 static_assert(std::is_same_v<decltype(std::function{Except2{}}), std::function<int(int*, long*)>>);
30
31 struct ExceptD {
32 static int operator()(int*, long* = nullptr) { return 0; }
33 };
34 static_assert(std::is_same_v<decltype(std::function{ExceptD{}}), std::function<int(int*, long*)>>);
35
36 struct Noexcept {
37 static int operator()(int*, long*) noexcept { return 0; }
38 };
39
40 static_assert(std::is_same_v<decltype(std::function{Noexcept{}}), std::function<int(int*, long*)>>);