Re: Working with std::variant reduction

Michael Powell <[email protected]> Wed, 31 Oct 2018 19:47:24 -0400
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMEoF_GwNSf+VuNY_QbiozcHDShmWLUC7wo9Fdia+hUa_OZBwA@mail.gmail.com>
On Wed, Oct 31, 2018 at 7:21 PM Michael Powell <[email protected]> wrote:
>
> Hello,
>
> If I've got a rule that goes something like this:
>
> type %= lit("double")
>     | lit("float")
>     | lit("int32")
>     | lit("int64")
>     | lit("uint32")
>     | lit("uint64")
>     | lit("sint32")
>     | lit("sint64")
>     | lit("fixed32")
>     | lit("fixed64")
>     | lit("sfixed32")
>     | lit("sfixed64")
>     | lit("bool")
>     | lit("string")
>     | lit("bytes")
>     | msg_type
>     | enum_type
>     ;

Actually, the thought occurs to me I could potentially help the
reduction out a little with this:

type %= (
    lit("double")
    | lit("float")
    | lit("int32")
    | lit("int64")
    | lit("uint32")
    | lit("uint64")
    | lit("sint32")
    | lit("sint64")
    | lit("fixed32")
    | lit("fixed64")
    | lit("sfixed32")
    | lit("sfixed64")
    | lit("bool")
    | lit("string")
    | lit("bytes")
    )
        | msg_type
        | enum_type
    ;

> Where the literals are the literals, and msg_type and enum_type are
> both rules that produce element_type_t(), is it sufficient to
> configure the type rule to produce std::variant<std::string,
> element_type_t>? Or in my case, adapted via struct.
>
> My apprehension, of course, is that I would have to exhaustively list
> the variant types: i.e. std::variant<std::string, std::string, ...,
> element_type_t, element_type_t>.
>
> Thanks!
>
> Cheers,
>
> Michael Powell