template <typename PointT, std::size_t N, std::size_t... Is>
PointT to(std::array<double, N> const& a, std::index_sequence<Is...>)
{
return PointT(a[Is]...);
}
template <typename PointT, std::size_t N>
PointT to(std::array<double, N> const& a)
{
return to<PointT>(a, std::make_index_sequence<N>{});
}
DEMO
Uwaga: index_sequence
/integer_sequence
narzędzia są dostępne począwszy od C++ 14. Ponieważ pytanie jest oznaczone jako C++11
, kod demo z tej odpowiedzi wykorzystuje następujące realizacji:
namespace std
{
template <std::size_t... Is>
struct index_sequence {};
template <std::size_t N, std::size_t... Is>
struct make_index_sequence_h : make_index_sequence_h<N - 1, N - 1, Is...> {};
template <std::size_t... Is>
struct make_index_sequence_h<0, Is...>
{
using type = index_sequence<Is...>;
};
template <std::size_t N>
using make_index_sequence = typename make_index_sequence_h<N>::type;
}
* „Moje pytanie brzmi: czy jest jakiś sposób, aby rozwinąć wachlarz się?” * Tak, ale ona jest brzydka. Nie możesz przekazać pary iteratorów do konstruktora 'PointT'? – dyp