Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++17でstd::tupleからstd::arrayに変換するラッパー関数 #615

Open
t-sakashita opened this issue Aug 7, 2024 · 2 comments
Open
Assignees
Milestone

Comments

@t-sakashita
Copy link
Owner

https://stackoverflow.com/questions/10604794/how-do-you-convert-a-homogeneous-stdtuple-to-a-stdarray

@t-sakashita
Copy link
Owner Author

t-sakashita commented Aug 7, 2024

std::applyを用いる。

@t-sakashita
Copy link
Owner Author

関数の定義:

template<typename TUPLE>
constexpr auto to_array(TUPLE && tuple) {
  constexpr auto make_array = [](auto&& ... x) {
    return std::array{std::forward<decltype(x)>(x) ... };
  };

  return std::apply(make_array, std::forward<TUPLE>(tuple));
}

@t-sakashita t-sakashita added this to the Big crunch milestone Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant