{#-
 # Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 # Copyright (C) 2024  OpenCyphal Development Team  <opencyphal.org>
 # This software is distributed under the terms of the MIT License.
#}
    class VariantType final : public cetl::variant<
{%- for field in composite_type.fields_except_padding %}
        {{ field.doc | block_comment('cpp-doxygen', 8, 120) }}
        _traits_::TypeOf::{{field.name|id}}{% if not loop.last %},{% endif %}
{%- endfor %}
    >
    {
    public:

        static const constexpr std::size_t variant_npos = cetl::variant_npos;

        using Base = cetl::variant<
{%- for field in composite_type.fields_except_padding %}
            _traits_::TypeOf::{{field.name|id}}{% if not loop.last %},{% endif %}
{%- endfor %}
        >;

        using Base::Base;

        struct IndexOf final
        {
            IndexOf() = delete;
{%- for field in composite_type.fields_except_padding %}
            static constexpr const std::size_t {{ field.name | id }} = {{ loop.index0 }}U;
{%- endfor %}
        };
        static constexpr const std::size_t MAX_INDEX = {{ composite_type.fields_except_padding  | length }}U;

        template<size_t I, typename T>
        struct alternative;

        template<size_t I, typename... Types>
        struct alternative<I, cetl::variant<Types...>> final
        {
            using type = typename cetl::variant_alternative<I, cetl::variant<Types...>>::type;
        };

        template<size_t I, typename T>
        struct alternative<I, const T> final
        {
            using type = std::add_const_t<typename cetl::variant_alternative<I, T>::type>;
        };

        template<std::size_t I, class... Types>
        static constexpr typename alternative<I, cetl::variant<Types...>>::type* get_if(cetl::variant<Types...>* v) noexcept
        {
            return cetl::get_if<I, Types...>(v);
        }

        template<std::size_t I, class... Types>
        static constexpr const typename alternative<I, cetl::variant<Types...>>::type* get_if(const cetl::variant<Types...>* v) noexcept
        {
            return cetl::get_if<I, Types...>(v);
        }

    };

    VariantType union_value;
