Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:13:07+00:00 2026-05-28T04:13:07+00:00

#include <tuple> #include <vector> #include <string> #include <iostream> //————————————————————————- #include <boost/spirit/include/karma.hpp> #include <boost/fusion/adapted/std_tuple.hpp> //————————————————————————-

  • 0
#include <tuple>
#include <vector>
#include <string>
#include <iostream>
//-------------------------------------------------------------------------
#include <boost/spirit/include/karma.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
//-------------------------------------------------------------------------
namespace ph = boost::phoenix;
namespace karma = boost::spirit::karma;
typedef std::back_insert_iterator<std::string> Sink;
typedef std::tuple<double,int> Data;
typedef std::vector<Data> Container;
struct Generator : karma::grammar<Sink,Container()>
{
  Generator(void) : Generator::base_type(start,"Generator")
  {
    start = data % karma::eol;
    //data = karma::delimit[???];
    return;
  }
  karma::rule<Sink,Container()> start;
  karma::rule<Sink,Data()> data;
};
//-------------------------------------------------------------------------
int main(int argc,char** argv)
{
  Generator generator;
  Container container;
  container.push_back(Data(3.1415,100500));
  container.push_back(Data(2.7183,9000));
  std::string result;
  Sink sink(result);
  bool b = boost::spirit::karma::generate(sink,generator,container);
  std::cerr << (b == true ? result : std::string("Error!")) << std::endl;
  return 0;
}

in rule data (as example) I need generate int before double and make with it arithmetical operation. How can I get access to elements of synthesized attribute (tuple) in semantic actions of data rule?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:13:08+00:00Added an answer on May 28, 2026 at 4:13 am

    The quickest solution I can come up with at this instant is simply:

    data = delimit [ int_ [ _1 = at_c<1>(_val) ] << double_ [ _1 = at_c<0>(_val) ] ];
    

    So, a full sample would look like:

    #include <boost/spirit/include/karma.hpp>
    #include <boost/spirit/include/phoenix.hpp>
    #include <boost/spirit/include/phoenix_operator.hpp>
    
    #include <boost/fusion/adapted.hpp>
    #include <boost/tuple/tuple.hpp>
    //-------------------------------------------------------------------------
    namespace ph = boost::phoenix;
    namespace karma = boost::spirit::karma;
    typedef std::back_insert_iterator<std::string> Sink;
    typedef boost::tuple<double,int> Data;
    typedef std::vector<Data> Container;
    struct Generator : karma::grammar<Sink,Container()>
    {
        Generator(void) : Generator::base_type(start,"Generator")
        {
            using namespace karma;
            using namespace ph;
            data = delimit [ int_ [ _1 = at_c<1>(_val) ] << double_ [ _1 = at_c<0>(_val) ] ];
            start = data % eol;
            return;
        }
        karma::rule<Sink,Container()> start;
        karma::rule<Sink,Data()> data;
    };
    //-------------------------------------------------------------------------
    int main(int argc,char** argv)
    {
        Generator generator;
        Container container;
        container.push_back(Data(3.1415,100500));
        container.push_back(Data(2.7183,9000));
        std::string result;
        Sink sink(result);
        bool b = boost::spirit::karma::generate(sink,generator,container);
        std::cerr << (b == true ? result : std::string("Error!")) << std::endl;
        return 0;
    }
    

    Output:

    100500 3.142
    9000 2.718
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to build the following simple example #include <boost/python.hpp> using namespace boost::python; tuple head_and_tail(object
Here is a code sample: // file main.cpp #include <iostream> #include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp>
The following piece of code #include <iostream> #include <vector> #include <tuple> using namespace std;
If I include both gtest/gtest.h and boost/math/distributions/poisson.hpp I get /opt/local/include/boost/tr1/tuple.hpp:63: error: ‘tuple’ is already
#include <list> #include <boost/tuple/tuple.hpp> template<class InputIterator> void f(InputIterator it) { typedef boost::tuple<typename InputIterator::value_type, int>
I have the following: #include<iostream> #include<unordered_map> #include<tuple> using namespace std; class CTest { //
Why does tuple documentation say to use, for example: #include boost/tuple/tuple.hpp and not #include
#include <iostream> using namespace std; int main() { double u = 0; double w
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.