这些天(c++17
)很容易:
auto const pusher([](auto& v) noexcept
{
return [&](auto&& ...e)
{
(
(
v.push_back(std::forward<decltype(e)>(e))
),
...
);
};
}
);
pusher(TestVector)(2, 5, 8, 11, 14);
编辑:对于真正喜欢冒险的人(c++20):
template <typename F, class Tuple>
constexpr void operator|(Tuple&& t, F f)
{
[&]<auto ...I>(std::index_sequence<I...>) noexcept(noexcept((f(std::get<I>(t)), ...)))
{
(f(std::get<I>(t)), ...);
}
(std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<Tuple>>>());
}
std::forward_as_tuple(2, 5, 8, 11, 14) | [&](auto&& e){ TestVector.push_back(std::forward<decltype(e)>(e)); }