Re: struct puzzle

Seth <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 12-04-17 18:15, Patrick Welche wrote:
> Following Seth's excellent example, the attached simple program parses
> an int and a map of strings. The puzzle is why it no longer compiles
> when I remove the int with the following patch:
I think it's the single-element fusion sequence edge-case again.

This has been a pain-point in Qi for a long time, and apparently still
crops up in X3 in specific circumstances (looks like, detecting whether
the bound argument in context is a container fails since it's a sequence
containing just the container).

This is very hard to get right - given the C++ type system and methods
to do meta-programming, I think. For now I'd accept the workaround of
adding padding on single-element (adapted) fusion sequences with a
container element.

    struct result {
        Map both;
        //
        boost::spirit::x3::unused_type padding;
    };

    BOOST_FUSION_ADAPT_STRUCT(result, padding, both)

            auto placebo_ = attr(nullptr);
            auto all_     = placebo_ >> +map_;

It's not pretty, but at least you know why.

Note that you can trivially use something non-x3 instead of unused_type:

    struct Blackhole {
        template <typename T> Blackhole& operator=(T&&) { return *this; }
    };

    struct result {
        Map both;
        //
        Blackhole padding;
    };


See http://coliru.stacked-crooked.com/a/7a55bf8e1529c3f4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.