Console Library
8.0.0
A header-only library that makes C++ simple
Toggle main menu visibility
Loading...
Searching...
No Matches
params.h
Go to the documentation of this file.
1
10
11
/*
12
Copyright (c) 2026 MrXie1109
13
14
Permission is hereby granted, free of charge, to any person obtaining a copy
15
of this software and associated documentation files (the "Software"), to deal
16
in the Software without restriction, including without limitation the rights
17
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
copies of the Software, and to permit persons to whom the Software is
19
furnished to do so, subject to the following conditions:
20
21
The above copyright notice and this permission notice shall be included in all
22
copies or substantial portions of the Software.
23
24
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
SOFTWARE.
31
*/
32
33
#pragma once
34
#include <type_traits>
35
#include <utility>
36
37
namespace
console
{
47
template
<
class
... Ts>
48
class
Params
;
49
55
template
<>
56
class
Params
<> {
57
public
:
61
Params
() =
default
;
62
69
template
<
class
F>
70
auto
apply
(F f)
const
->
decltype
(f()) {
71
return
f();
72
}
73
};
74
81
template
<
class
T>
82
class
Params
<
T
> {
83
T
value
;
84
85
public
:
90
Params
(
const
T &
value
) :
value
(
value
) {}
91
99
template
<
class
F>
100
auto
apply
(F f)
const
->
decltype
(f(
value
)) {
101
return
f(
value
);
102
};
103
};
104
113
template
<
class
T,
class
... Rest>
114
class
Params
<
T
, Rest...> {
115
T
value
;
116
Params
<Rest...>
rest
;
117
125
template
<
class
F>
126
struct
Helper
{
127
F
f
;
128
const
T
&
value
;
129
135
Helper
(F
f
,
const
T &
value
) :
f
(
f
),
value
(
value
) {}
136
144
template
<
class
... Args>
145
auto
operator()
(
const
Args &...args)
const
146
->
decltype
(
f
(
value
, args...)) {
147
return
f
(
value
, args...);
148
}
149
};
150
151
public
:
157
Params
(
const
T &
value
,
const
Rest &...
rest
) :
158
value
(
value
),
rest
(
rest
...) {}
159
168
template
<
class
F>
169
auto
apply
(F f)
const
->
decltype
(
rest
.apply(
Helper<F>
(f,
value
))) {
170
return
rest
.apply(
Helper<F>
(f,
value
));
171
}
172
};
173
184
template
<
class
... Ts>
185
Params<typename std::decay<Ts>::type
...>
params
(Ts &&...values) {
186
return
{std::forward<Ts>(values)...};
187
}
188
}
console::Params< T, Rest... >::rest
Params< Rest... > rest
剩余参数的包装器
Definition
params.h:116
console::Params< T, Rest... >::apply
auto apply(F f) const -> decltype(rest.apply(Helper< F >(f, value)))
将存储的所有参数应用于可调用对象。
Definition
params.h:169
console::Params< T, Rest... >::Params
Params(const T &value, const Rest &...rest)
从多个值构造多参数 Params。
Definition
params.h:157
console::Params< T, Rest... >::value
T value
当前参数值
Definition
params.h:115
console::Params< T >::apply
auto apply(F f) const -> decltype(f(value))
将存储的参数应用于可调用对象。
Definition
params.h:100
console::Params< T >::Params
Params(const T &value)
从给定值构造单参数 Params。
Definition
params.h:90
console::Params< T >::value
T value
存储的参数值
Definition
params.h:83
console::Params<>::apply
auto apply(F f) const -> decltype(f())
将存储的参数应用于可调用对象。
Definition
params.h:70
console::Params<>::Params
Params()=default
无参构造函数。
console::Params
递归参数包包装器,将多个参数存储为值类型,并支持通过 apply 方法延迟调用。
Definition
params.h:48
console
本库所有组件所在的顶层命名空间。
console::Key::T
@ T
Definition
kb.h:99
console::params
Params< typename std::decay< Ts >::type... > params(Ts &&...values)
便捷函数,用于构造 Params 对象。
Definition
params.h:185
console::Params< T, Rest... >::Helper
辅助函数对象,用于在 apply 过程中将当前参数与剩余参数合并。
Definition
params.h:126
console::Params< T, Rest... >::Helper::value
const T & value
当前参数值的引用
Definition
params.h:128
console::Params< T, Rest... >::Helper::f
F f
用户提供的可调用对象
Definition
params.h:127
console::Params< T, Rest... >::Helper::operator()
auto operator()(const Args &...args) const -> decltype(f(value, args...))
调用辅助函数对象。
Definition
params.h:145
console::Params< T, Rest... >::Helper::Helper
Helper(F f, const T &value)
构造 Helper 对象。
Definition
params.h:135
include
util
params.h
Generated on
for Console Library by
1.18.0