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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:34:49+00:00 2026-05-19T12:34:49+00:00

I’m writing a lexigraphical analyser. It takes an English string, and converts it into

  • 0

I’m writing a lexigraphical analyser. It takes an English string, and converts it into a set of latitude/longitude co-ordinates. It’s a bit like Google Earth.

Anyway, I’ve written my symbol tables and grammar, and it’s happily parsing formatted data.

struct LatLongDegrees
{
 std::string  dirLat_;
 double   degLat_;
 std::string     dirLong_;
 double   degLong_;
}

For example: {“North”, 23.59, “East”, -30.82}

Here is my grammar:

 basic =(latitude >> ' ' >> double_ >> ' ' >> longitude >> ' ' >> double_);

Where latitude and longitude are symbol tables that map from shorthand compass directions to strings (eg “e” to “East”)

So, on to my question:

I want to add the following rule to my grammar, where the latitude and longitude symbols are in the opposite positions:

reversed = (longitude  >> ' ' >> double_ >> ' ' >> latitude >> double_ )

This parses, BUT the degLat_ and degLong_ values are not reversed along with string values. They are simply parsed directly into the struct, without regard for the string labels.

How do I build a struct (or boost::fusion vector) when the data to be parsed is not sequential?

  • 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-19T12:34:50+00:00Added an answer on May 19, 2026 at 12:34 pm

    You have several possibilities. The easiest is to adapt your struct into a Fusion sequence in the required order:

    BOOST_FUSION_ADAPT_STRUCT(
        LatLongDegrees,
        (std::string, dirLong_)
        (double, degLong_)
        (std::string, dirLat_)
        (double, degLat_)
    );
    

    (yes, the order of adaptation does not have to match the order of the members in the original struct, you can even leave out members or duplicate them). This works fine if you have one particular order you want to parse your members in.

    If you need different orderings in the same program, you might want to utilize a similar adaptation mechanism, but which additionally allows to give a name to the adapted struct:

    BOOST_FUSION_ADAPT_STRUCT_NAME(
        LatLongDegrees, reversed_LatLongDegrees,
        (std::string, dirLong_)
        (double, degLong_)
        (std::string, dirLat_)
        (double, degLat_)
    );
    

    where reversed_LatLongDegrees is the data type used as the attribute in your Spirit grammar:

    rule <Iterator, reversed_LatLongDegrees()> reversed;
    reversed = longitude  >> ' ' >> double_ >> ' ' >> latitude >> double_;
    
    LatLongDegrees data;
    parse(begin, end, reversed, data);
    

    This allows to create several adaptations for the same struct at the same time.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am writing an app with both english and french support. The app requests
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into

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.