Sequoia
Loading...
Searching...
No Matches
Utilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2019. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
15
16#include <utility>
17#include <tuple>
18#include <scoped_allocator>
19
20namespace sequoia
21{
22 template<class Fn, class... Ts, std::size_t... I>
23 requires std::invocable<Fn, decltype(std::get<I>(std::declval<std::tuple<Ts&&...>>()))...>
24 auto invoke_with_specified_args(Fn f, std::index_sequence<I...>, [[maybe_unused]] Ts&&... ts)
25 {
26 return f(std::get<I>(std::tuple<Ts&&...>{std::forward<Ts>(ts)...})...);
27 }
28
29 template<class F> struct function_signature;
30
31 template<class R, class L, class T>
32 struct function_signature<R(L::*) (T)>
33 {
34 using ret = R;
35 using arg = T;
36 };
37
38 template<class R, class L, class T>
39 struct function_signature<R(L::*) (T) const>
40 {
41 using ret = R;
42 using arg = T;
43 };
44
45 template<class R, class L, class T>
46 struct function_signature<R(L::*) (T) noexcept>
47 {
48 using ret = R;
49 using arg = T;
50 };
51
52 template<class R, class L, class T>
53 struct function_signature<R(L::*) (T) const noexcept>
54 {
55 using ret = R;
56 using arg = T;
57 };
58
59 template<class R, class T>
60 struct function_signature<R(*) (T)>
61 {
62 using ret = R;
63 using arg = T;
64 };
65
66 template<class R, class T>
67 struct function_signature<R(*) (T) noexcept>
68 {
69 using ret = R;
70 using arg = T;
71 };
72
73 template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
74 template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
75
76 template<alloc A>
78 {
79 constexpr static std::size_t size{1};
80 };
81
82 template<alloc OuterAlloc, alloc... InnerAlloc>
83 struct alloc_count<std::scoped_allocator_adaptor<OuterAlloc, InnerAlloc...>>
84 {
85 constexpr static std::size_t size{1 + sizeof...(InnerAlloc)};
86 };
87}
Concepts which are sufficiently general to appear in the sequoia namespace.
A concept for allocators.
Definition: Concepts.hpp:48
Definition: Utilities.hpp:78
Definition: Utilities.hpp:29
Definition: Utilities.hpp:73