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

  • Home
  • SEARCH
  • 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 433253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:09:20+00:00 2026-05-12T20:09:20+00:00

I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the

  • 0

I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the same time. (I’m sorry for the lengthly question, but I think I should use an example..)

Here an example: Suppose I want to produce N objects in a factory and for each object I have a demand to fulfill (this demand is known at creation of the multi-index).
Well, within my algorithm I get intermediate results, which I store in the following class:

class intermediate_result
{
private:
    std::vector<int>   parts;     // which parts are produced
    int                used_time; // how long did it take to produce

    ValueType          max_value; // how much is it worth
};

The vector parts descibes, which objects are produced (its length is N and it is lexicographically smaller then my coresp demand-vector!) – for each such vector I know the used_time as well. Additionally I get a value for this vector of produced objects.

I got another constraint so that I can’t produce every object – my algorithm needs to store several intermediate_result-objects in a data-structure. And here boost::multi_index_container is used, because the pair of parts and used_time describes a unique intermediate_result (and it should be unique in my data-structure) but the max_value is another index I’ll have to consider, because my algorithm always needs the intermediate_result with the highest max_value.

So I tried to use boost::multi_index_container with ordered_unique<> for my “parts&used_time-pair” and ordered_non_unique<> for my max_value (different intermediate_result-objects may have the same value).

The problem is: the predicate, which is needed to decide which “parts&used_time-pair” is smaller, uses std::lexicographical_compare on my parts-vector and hence is very slow for many intermediate_result-objects.
But there would be a solution: my demand for each object isn’t that high, therefore I could store on each possible parts-vector the intermediate results uniquely by its used_time.

For example: if I have a demand-vector ( 2 , 3 , 1) then I need a data-structure which stores (2+1)*(3+1)*(1+1)=24 possible parts-vectors and on each such entry the different used_times, which have to be unique! (storing the smallest time is insufficient – for example: if my additional constraint is: to meet a given time exactly for production)

But how do I combine a random_access<>-index with an ordered_unique<>-index?
(Example11 didn’t help me on this one..)

  • 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-12T20:09:21+00:00Added an answer on May 12, 2026 at 8:09 pm

    (I had to use an own answer to write code-blocks – sorry!)

    The composite_key with used_time and parts (as Kirill V. Lyadvinsky suggested) is basically what I’ve already implemented. I want to get rid of the lexicographical compare of the parts-vector.

    Suppose I’ve stored the needed_demand somehow then I could write a simple function, which returns the correct index within a random-access data-structure like that:

    int get_index(intermediate_result &input_result) const
    {
        int ret_value  = 0;
        int index_part = 1;
        for(int i=0;i<needed_demand.size();++i)
        {
            ret_value  += input_result.get_part(i) * index_part;
            index_part *= (needed_demand.get_part(i) + 1);
        }
    }
    

    Obviously this can be implemented more efficiently and this is not the only possible index ordering for the needed demand. But let’s suppose this function exists as a member-function of intermediate_result! Is it possible to write something like this to prevent lexicographical_compare ?

    indexed_by<
      random_access< >,      
      ordered_unique< 
        composite_key< 
          intermediate_result,
          member<intermediate_result, int, &intermediate_result::used_time>,
          const_mem_fun<intermediate_result,int,&intermediate_result::get_index>
        >
      >
    >
    

    If this is possible and I initialized the multi-index with all possible parts-vectors (i.e. in my comment above I would’ve pushed 24 empty maps in my data-structure), does this find the right entry for a given intermediate_result in constant time (after computing the correct index with get_index) ?
    I have to ask this, because I don’t quite see, how the random_access<> index is linked with the ordered_unique<> index..

    But thank you for your answers so far!!

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

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Found the solution!! Here's the code that works: RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}… May 12, 2026 at 11:21 pm
  • Editorial Team
    Editorial Team added an answer Storing the salt unencrypted in the database next to the… May 12, 2026 at 11:21 pm
  • Editorial Team
    Editorial Team added an answer Working with dynamic table names is trivial in Ibatis. Just… May 12, 2026 at 11:21 pm

Related Questions

I am wanting to write some cross-platform library code. I am creating a library
I have a html table that I reorder based on a CSV list of
I have class foo that contains a std::auto_ptr member that I would like to
I am creating a C++ Win32 dll with some global data. There is a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.