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 8459759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:25:04+00:00 2026-06-10T13:25:04+00:00

Maybe a noob question, I’ve a piece of code like this: struct S {

  • 0

Maybe a noob question, I’ve a piece of code like this:

struct S {
    S() {...}
    S(int v) {
        // ...
    }
};
qi::rule<const char*, S(), boost::spirit::ascii::space_type> ip=qi::int_parser<S()>();
qi::rule<const char*, std::vector<S>(), boost::spirit::ascii::space_type> parser %= ip % ',';
...

Rules above can work, but the code breaks if S constructors require additional parameters, such as:

struct S {
    S(T t) {...}
    S(T t, int v) {
        // ...
    }
};

I’ve spent days to find solution, but no luck so far.
Can anyone help?

  • 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-06-10T13:25:05+00:00Added an answer on June 10, 2026 at 1:25 pm

    There is no direct way, but you can probably explicitely initialize things:

    qi::rule<It, optional<S>(), Skipper> myrule;
    
    myrule %= 
           qi::eps [ _val = phoenix::construct<S>(42) ] >>
           int_parser<S()>;
    

    However, since you are returning it from the int_parser, my intuition says that default-initialization should be appropriate (or perhaps the type S doesn’t have a single, clear, responsibility?).

    Edit

    In response to the comment, it looks like you want this:

    T someTvalue;    
    
    myrule = qi::int_ 
       [ qi::_val = phx::construct<S>(someTvalue, qi::_1) ];
    

    Or, if someTvalue is a variable outside the grammar constructor, and may change value during execution of the parser (and it lives long enough!), you could do

    myrule = qi::int_ 
       [ qi::_val = phx::construct<S>(phx::ref(someTvalue), qi::_1) ];
    

    Hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This maybe a noob question, however, I haven't been able to find a suitable
This sounds like a noob question for me but I need to ask it.
Ok, it seems like I'm asking a noob question (maybe I am and I
i am new to WPF so maybe this will be noob question but i
I'am new to Castle and Castle.Windsor, so this is maybe a noob question. I
Maybe this is a noob question, i have an NSURL from savePanel, and i
maybe this is a noob question, but I'm receiving some data over TCP and
This maybe a noob question but please help me. I found a library called
Maybe this is a poor question, but, I can't find a tutorial or even
Hi Sorry for this noob question but here goes...i have a working slidetoggle on

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.