Re: How to synthesize std::map

Michael Powell <[email protected]> Fri, 11 Jan 2019 12:27:29 -0500
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMEoF_H3mOwE1AaJPZfhgM5cOcrDCHeNTSvfF__o8Eam+7LFMA@mail.gmail.com>
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

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