Re: [Spirit Devel] [ADAPT_ADT and Karma] ADAPT_ADT causes grammars with variants to not compile in karma

Robert Nelson <[email protected]> Fri, 10 Dec 2010 11:15:38 -0700
Newsgroups gmane.comp.parsers.spirit.devel
Message-ID <[email protected]>
Just as a follow up, I found a really nice solution to my problem shortly
after we had this conversation.  I used the BOOST_FUSION_ADAPT_STRUCT_MACRO
with functions that return a reference.  This eliminates the proxy class,
while still providing the exact same level of abstraction as
BOOST_FUSION_ADAPT_ADT as far as karma is concerned since karma doesn't use
the set functions defined in ADAPT_ADT.

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev

_______________________________________________
Spirit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
main.cpp (text/x-c++src, 1 KB)
#include <boost/spirit/include/karma.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/home/support/adapt_adt_attributes.hpp>
#include <boost/variant/variant.hpp>
#include <string>

typedef const boost::variant<std::string,unsigned int> const_variant_type;
typedef const boost::variant<std::string,unsigned int> variant_type;

struct y
{
  variant_type data;
  const_variant_type& get() const {return data;}
  variant_type& get() {return data;}
};

BOOST_FUSION_ADAPT_STRUCT(y,(variant_type,get()))

int main()
{
  using namespace boost::spirit::karma;
  using namespace boost::phoenix;
  boost::spirit::karma::rule<std::string::iterator,std::string()> a;
  boost::spirit::karma::rule<std::string::iterator,unsigned int()> b;
  boost::spirit::karma::rule<std::string::iterator,y()> Y;
  Y = (a | b)[_1 = at_c<0>(_val)];
}