mercredi 23 septembre 2015

Compile time array from C++ template parameter pack

How can I at compile time create for example an std::array from a template parameter pack?

This shows what need, but without parameter pack.

template<typename T1, typename T2, typename T3>
struct ToInfoArray
{
    static constexpr std::array<Info, 3> value = { { T1::info, T2::info, T3::info } };
};

Live demo demonstrating the intended usage

Bonus question: Would you use std::array, array[] or std::initializer_list as type for InfoList?

Aucun commentaire:

Enregistrer un commentaire