t-sakashita / rokko

Integrated Interface for libraries of eigenvalue decomposition
Boost Software License 1.0
10 stars 2 forks source link

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

Open t-sakashita opened 1 month ago

t-sakashita commented 1 month ago

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

t-sakashita commented 1 month ago

std::applyを用いる。

t-sakashita commented 1 month ago

関数の定義:

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));
}