mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 12:12:15 +02:00
OptionList: support variadic template parameter pack in constructors
This allows usage such as: const OptionList opt(Option("dev", "tun"), Option("remote", "openvpn.example.com", "1194", "udp")); Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
parent
8a012b4545
commit
322ae24b53
@ -104,7 +104,7 @@ namespace openvpn {
|
||||
Option(T first, Args... args)
|
||||
{
|
||||
reserve(1 + sizeof...(args));
|
||||
from_list(first, args...);
|
||||
from_list(std::move(first), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static validate_status validate(const std::string& str, const size_t max_len)
|
||||
@ -360,8 +360,8 @@ namespace openvpn {
|
||||
template<typename T, typename... Args>
|
||||
void from_list(T first, Args... args)
|
||||
{
|
||||
from_list(first);
|
||||
from_list(args...);
|
||||
from_list(std::move(first));
|
||||
from_list(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
volatile mutable bool touched_ = false;
|
||||
@ -661,6 +661,18 @@ namespace openvpn {
|
||||
}
|
||||
};
|
||||
|
||||
OptionList()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
OptionList(T first, Args... args)
|
||||
{
|
||||
reserve(1 + sizeof...(args));
|
||||
from_list(std::move(first), std::forward<Args>(args)...);
|
||||
update_map();
|
||||
}
|
||||
|
||||
static OptionList parse_from_csv_static(const std::string& str, Limits* lim)
|
||||
{
|
||||
OptionList ret;
|
||||
@ -1412,6 +1424,18 @@ namespace openvpn {
|
||||
OPENVPN_THROW(option_error, "line " << line_num << " is too long");
|
||||
}
|
||||
|
||||
void from_list(Option opt)
|
||||
{
|
||||
push_back(std::move(opt));
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void from_list(T first, Args... args)
|
||||
{
|
||||
from_list(std::move(first));
|
||||
from_list(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
IndexMap map_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user