spirit::karma specialization for std::optional (C++17)
Emiliano Canedo <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAMnrcdyB75bMY4rV33GNvsWPTr1TEFyyMaXjc7mBxW1bnqbOvA@mail.gmail.com> |
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?
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