Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Traits.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#ifndef TOOLBOX_UTIL_TRAITS_HPP
18#define TOOLBOX_UTIL_TRAITS_HPP
19
20#include <tuple>
21
22namespace toolbox {
23inline namespace util {
24
26template <typename TypeT>
27struct FunctionTraits : FunctionTraits<decltype(&TypeT::operator())> {};
28
30template <typename ReturnT, typename... ArgsT>
31struct FunctionTraits<ReturnT (*)(ArgsT...)> {
32
33 using FunctionType = ReturnT (*)(ArgsT...);
34 using ClassType = void;
36
37 enum { Arity = sizeof...(ArgsT) };
38
39 template <std::size_t i>
40 using ArgType = std::tuple_element_t<i, std::tuple<ArgsT...>>;
41
42 // Apply parameter pack to template.
43 template <template <typename...> typename TemplT>
44 using Pack = TemplT<ArgsT...>;
45};
46
48template <typename ReturnT, typename... ArgsT>
50
52template <typename ClassT, typename ReturnT, typename... ArgsT>
53struct FunctionTraits<ReturnT (ClassT::*)(ArgsT...)> : FunctionTraits<ReturnT (*)(ArgsT...)> {
54 using FunctionType = ReturnT (ClassT::*)(ArgsT...);
56};
57
59template <typename ClassT, typename ReturnT, typename... ArgsT>
60struct FunctionTraits<ReturnT (ClassT::*)(ArgsT...) const> : FunctionTraits<ReturnT (*)(ArgsT...)> {
63};
64
66template <typename ClassT, typename ReturnT, typename... ArgsT>
68: FunctionTraits<ReturnT (*)(ArgsT...)> {
71};
72
74template <typename ClassT, typename ReturnT, typename... ArgsT>
75struct FunctionTraits<ReturnT (ClassT::*)(ArgsT...) noexcept>
76: FunctionTraits<ReturnT (*)(ArgsT...)> {
79};
80
81} // namespace util
82} // namespace toolbox
83
84#endif // TOOLBOX_UTIL_TRAITS_HPP
constexpr auto bind() noexcept
Definition Slot.hpp:92
std::tuple_element_t< i, std::tuple< ArgsT... > > ArgType
Definition Traits.hpp:40
Default case for functors and lambdas.
Definition Traits.hpp:27