Re: How to synthesize std::map

Michael Powell <[email protected]> Fri, 11 Jan 2019 12:40:01 -0500
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMEoF_H-nYJbLM4NTm8OtwMB9K3MoGtwVpihJZ_KAf5nk83Wcg@mail.gmail.com>
On Fri, Jan 11, 2019 at 12:35 PM Michael Powell <[email protected]> wrote:
>
> At least according to this article dated just over nine years ago,
> this should be working I think:
>
> http://boost-spirit.com/home/articles/qi-example/parsing-a-list-of-key-value-pairs-using-spirit-qi/
>
> What changed since then? Obviously, a whole lot, but what changed?
> What else do I need to be doing now?

Ah, I see... And Mr. Heller's response was very helpful:

#include <boost/fusion/include/std_pair.hpp>

After that, Boost.Fusion was happy with Std.Pair, Std.Map, etc.

> On Fri, Jan 11, 2019 at 12:32 PM Michael Powell <[email protected]> wrote:
> >
> > On Fri, Jan 11, 2019 at 12:27 PM Michael Powell <[email protected]> wrote:
> > >
> > > At least from the forums I've read, this should be working, I'm not
> > > sure why it's not working now, current Boost 1.69 Spirit Qi.
> > >
> > > https://wandbox.org/permlink/HxB6Yg3r9ZpbHOxt
> >
> > Even simplifying further, removing the key_t and grammar rule, for the
> > str_t, still does not work. Seems like a map/pair issue more than an
> > underlying key/str issue.
> >
> > https://wandbox.org/permlink/fmffEazGRMTnl5w9
> >
> > > On Fri, Jan 11, 2019 at 12:10 PM Michael Powell <[email protected]> wrote:
> > > >
> > > > Hello,
> > > >
> > > > Using Boost Spirit Qi, or std::unordered_map... I am receiving
> > > > assignment errors on build.
> > > >
> > > > Interestingly, I can map a Vector of Member Tuples without any compiler errors:
> > > >
> > > > std::vector<boost::tuple<key_t, value_t>> ...
> > > >
> > > > However attempting to map an Unordered Map does not seem to work as
> > > > well, or I need to do some additional work adapting it for Qi grammar
> > > > purposes:
> > > >
> > > > std::unordered_map<key_t, value_t> ...
> > > >
> > > > At least not without some help, perhaps... That or I need to do so in
> > > > one, swift rule.
> > > >
> > > > Assuming:
> > > >
> > > > using object_t = std::unordered_map<key_t, value_t>;
> > > > using member_t = object_t::node_type;
> > > >
> > > > For example, instead of:
> > > >
> > > > qi::rule<iterator_type, member_t(), skipper_type> member;
> > > > qi::rule<iterator_type, object_t(), skipper_type> object_;
> > > >
> > > > And which rules being defined as:
> > > >
> > > > member %= member_key >> ':' >> value_;
> > > >
> > > > object_ %= '{'
> > > >     >> (member % ',')
> > > >     >> '}';
> > > >
> > > > I wonder whether I need to just simplify and collapse the rules into one rule.
> > > >
> > > > object_ %= '{'
> > > >     >> ((member_key >> ':' >> value_) % ',')
> > > >     >> '}';
> > > >
> > > > With the compiler error being:
> > > >
> > > > 2>d:\dev\boost.org\boost_1_69_0\boost\spirit\home\qi\detail\assign_to.hpp(153):
> > > > error C2440: 'static_cast': cannot convert from 'const T_' to
> > > > 'Attribute'
> > > > 2>        with
> > > > 2>        [
> > > > 2>            T_=kingdom::json::key_t
> > > > 2>        ]
> > > > 2>        and
> > > > 2>        [
> > > > 2>            Attribute=std::_Node_handle<std::_List_node<std::pair<const
> > > > kingdom::json::key_t,kingdom::json::value_t>,std::_Default_allocator_traits<std::allocator<std::pair<const
> > > > kingdom::json::key_t,kingdom::json::value_t>>>::void_pointer>,std::allocator<std::pair<const
> > > > kingdom::json::key_t,kingdom::json::value_t>>,std::_Node_handle_map_base,kingdom::json::key_t,kingdom::json::value_t>
> > > > 2>        ]
> > > >
> > > > Thoughts? Suggestions?
> > > >
> > > > Cheers,
> > > >
> > > > Michael Powell