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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:29:41+00:00 2026-05-15T11:29:41+00:00

I’m currently using Boost’s multi-index to help keep track of how many times a

  • 0

I’m currently using Boost’s multi-index to help keep track of how many times a packet passes through a system.

Each time a system touches the packet, its IP address is added to a string, separated by commas. I go through that string then, tokenize it and add each IP found to a multi-index. Since the IPs are set to be unique right now, it’s impossible for the same IP to be added twice to the multi-index. What should happen then is the value associated with the IP address should be incremented, counting how many times the packet went through that same IP.

Anyways, my issue comes in here. When I use something like stl map, I will get back a response which lets me know a key could not be added due to a duplicate key already existing within the map. Does Boost’s multi-index offer anything similar? I know that if I attempt to insert the same IP it will fail, but how can I tell it failed?

Here’s a portion of my current code:

// Multi-index handling
using boost::multi_index_container;
using namespace boost::multi_index;

struct pathlog
{
    string         hop;
    int     passedthru;

    pathlog(std::string hop_,int passedthru_):hop(hop_),passedthru(passedthru_){}

    friend std::ostream& operator<<(std::ostream& os,const pathlog& e)
    {
        os<<e.hop<<" "<<e.passedthru<<std::endl;
        return os;
    }
};

// structs for data
struct hop{};
struct passedthru{};

// multi-index container setup
typedef multi_index_container<
pathlog,
indexed_by<
ordered_unique<
tag<hop>,  BOOST_MULTI_INDEX_MEMBER(pathlog,std::string,hop)>,
ordered_non_unique<
tag<passedthru>, BOOST_MULTI_INDEX_MEMBER(pathlog,int,passedthru)> >
> pathlog_set;


int disassemblepathlog(const string& str, pathlog_set& routecontainer, const string& delimiters = ","){
    // Tokenizer (heavily modified) from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html

    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        routecontainer.insert(pathlog((str.substr(lastPos, pos - lastPos)),1)); // if this fails, I need to increment the counter!
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}
  • 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-15T11:29:42+00:00Added an answer on May 15, 2026 at 11:29 am

    Your call to insert returns a std::pair< iterator, bool >. The bool will be true only if the insert succeeded.

    See http://www.boost.org/doc/libs/1_43_0/libs/multi_index/doc/reference/ord_indices.html#modifiers

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.