VCTR
Loading...
Searching...
No Matches
FunctionConcepts.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::detail
24{
25
26template <class, class>
27struct FunctionWithSignature : std::false_type
28{
29};
30
31template <class Fn, class Ret, class... Args>
32struct FunctionWithSignature<Fn, Ret (Args...)>
33{
34 static constexpr bool value = requires (Fn&& t, Ret (*fp) (Args...)) { fp = &t; };
35};
36
37template <class, class>
38struct FunctionWithSignatureOrImplicitlyConvertible : std::false_type
39{
40};
41
42template <class Fn, class Ret, class... Args>
43struct FunctionWithSignatureOrImplicitlyConvertible<Fn, Ret (Args...)>
44{
45 static constexpr bool value = requires (Fn&& t, Args&&... args) { { t (args...) } -> std::convertible_to<Ret>; };
46};
47
48} // namespace vctr::detail
49
50namespace vctr::is
51{
52
69template <class Fn, class Signature>
70concept functionWithSignature = detail::FunctionWithSignature<Fn, Signature>::value;
71
88template <class Fn, class Signature>
89concept functionWithSignatureOrImplicitlyConvertible = detail::FunctionWithSignatureOrImplicitlyConvertible<Fn, Signature>::value;
90
91} // namespace vctr::is
Constrains Fn to be a function with the specified function signature or some signature with implicitl...
Definition: FunctionConcepts.h:89
Constrains Fn to be a function with an exact function signature.
Definition: FunctionConcepts.h:70