Re: spirit::karma specialization for std::optional (C++17)
Michael <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On April 21, 2017 10:20:42 AM EDT, Emiliano Canedo <[email protected]> wrote: >Hello, > >I'm working in a spirit::karma specialization for std::optional >(C++17). I >have this code for now: > >//----------------------------------- > >namespace boost >{ >namespace spirit >{ >namespace traits >{ > >// This handles std::optional attributes >template <typename Attribute, typename Exposed> >struct extract_from_attribute<std::experimental::optional<Attribute>, >Exposed> >{ > typedef Attribute const& type; > template <typename Context> > static type call(std::experimental::optional<Attribute> const& attr, >Context& ctx) > { > return attr.value(); > } >}; > >template <typename Attribute, typename Exposed> >struct extract_from_attribute<std::experimental::optional<Attribute >const>, >Exposed> >{ > typedef Attribute const& type; > template <typename Context> > static type call(std::experimental::optional<Attribute const> const& >attr, Context& ctx) > { > return attr.value(); > } >}; > >} >} >} > >//----------------------------------- > >This works good to extract the value, but, I need to handle the calls >if >the optional have, or not, a value. I tried to understand how karma >handle >this for boost::optional, but I'm stuck with that. Any idea? Are you trying to invoke the output regardless of optional state? Or can you omit the output when optional does not have a value? >Thanks!! > > >------------------------------------------------------------------------ > >------------------------------------------------------------------------------ >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 -- Sent from my Android device with K-9 Mail. Please excuse my brevity. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot