LoginSignup
2
2

More than 5 years have passed since last update.

# C++のパラメータパックを順繰りに手繰る方法

Last updated at Posted at 2018-10-24

忘れっぽいのでとりあえず記するますですにゃーん

普通にぐるぐる回すだけ

template <typename Current, typename... Nexts>
auto func(Current&& c, Nexts&&... n) -> void {
    func(std::forward<Nexts>(n)...);
}

void func() {}

型だけで良けりゃ

template <typename Current, typename... Nexts>
auto func(std::tuple<Current, Nexts...>* = 0) -> void {
    func(static_cast<std::tuple<Nexts...>*>(nullptr));
}

auto func(std::tuple<>* = 0) {}

と思ったけどこっちがいいかもね

template <typename Current = void, typename... Nexts>
auto func() -> void {
    if constexpr(!std::is_same<Current, void>::value) func<Nexts...>();
}

参考

コレジャナイってな人はこっち https://qiita.com/_EnumHack/items/677363eec054d70b298d

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2