Dedukcja typu argumentu parametru w szablonie

0

Hej,
obecny kod wygląda następująco:

template<class Enumeration>
struct StructA
{
    template<Enumeration identifier>
    struct StructB
    {
        static_assert(std::is_enum_v<Enumeration>,
            "Enumeration must be enum type.");
        // ...
    };
};

Użycie tego jest dosyć uciążliwe, bo musimy najpierw podać typ Enuma, a dopiero wartość:

enum class JakisEnum
{
    A,
    B,
    C
};
using Properties = StructA<JakisEnum>::StructB<JakisEnum::A>;

Czy istnieje jakaś możliwość pominięcia podawania typu Enuma/ dedukcji typu?
StructB zawiera same statyczne elementy - statyczne ustawienia zależące od wartości enuma.

5

C++17

template<auto v>
struct foo
{
    using enumeration = decltype(v);
    static_assert(std::is_enum_v<enumeration>);

    static constexpr auto value = v;
};

https://wandbox.org/permlink/30PKv8lD2xMJttma

0

Tak, dokładnie o to chodziło, dzięki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1