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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:03:23+00:00 2026-06-03T15:03:23+00:00

I have just noticed that i am not able to make changes in the

  • 0

I have just noticed that i am not able to make changes in the boost multi index container elements. Is this true? (based on the following simplified code) look at the “update” function:

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>
namespace sim_mob
{
enum TrafficColor
{
    Red =1,             ///< Stop, do not go beyond the stop line.
    Amber = 2,          ///< Slow-down, prepare to stop before the stop line.
    Green = 3,          ///< Proceed either in the forward, left, or right direction.
    FlashingRed = 4,    ///future use
    FlashingAmber = 5,  ///future use
    FlashingGreen = 6   ///future use
};
//Forward declarations
class Link
{
public:
    int aa;
};

//////////////some bundling ///////////////////
using namespace ::boost;
using namespace ::boost::multi_index;

typedef struct
{
    sim_mob::Link *LinkTo;
    sim_mob::Link *LinkFrom;
//  ColorSequence colorSequence;
    TrafficColor currColor;
} linkToLink;


typedef multi_index_container<
    linkToLink,
    indexed_by<                                                                    // index
        random_access<>,//0
        ordered_non_unique< member<linkToLink,sim_mob::Link *, &linkToLink::LinkTo> >,  // 1
        ordered_non_unique< member<linkToLink,sim_mob::Link *, &linkToLink::LinkFrom> >  // 2
    >
> links_map;
class Phase
{
public:
    typedef links_map::nth_index_iterator<1>::type LinkTo_Iterator;
    Phase(double CycleLenght,std::size_t start, std::size_t percent): cycleLength(CycleLenght),startPecentage(start),percentage(percent){
    };

    void update(double lapse)
    {
        links_map_[0].currColor = Red;
    }

    std::string name;
private:
    sim_mob::links_map links_map_;

};
}//namespace

int main()
{
    sim_mob::Phase F(100,70,30);
}

No need to go through entire program. just note that, in the update method, I get this error:
multiIndex$ c++ exp2.cpp
exp2.cpp: In member function ‘void sim_mob::Phase::update(double)’:
exp2.cpp:69:29: error: assignment of member ‘sim_mob::linkToLink::currColor’ in read-only object

I just read in the boost tutorial that iterators only grant const access. How can I go around this issue?
thank you for your 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-03T15:03:25+00:00Added an answer on June 3, 2026 at 3:03 pm

    Three different ways of changing elements in a multi-index container. You can use links_map_.replace(iterator, new_value) to replace an existing element with a new one. You can use links_map_.modify(iterator, unaryFunctionObject) to change the element with a modifier object. And finally, if a member variable is not part of any index, you can declare it as mutable and change it directly. In your example, the latter should work fine.

    For the other two ways, take a look at the specification of the member function replace and modify in the Boost.MultiIndex Documentation.

    Edit: In your specific case, the approach with mutable might look like this:

    struct linkToLink
    {
        sim_mob::Link* LinkTo;
        sim_mob::Link* LinkFrom;
        // simplify write operations to this variable if used in a multi-index
        // container - bypassing the const-ness. This is possible, because the
        // variable is not part of any index.
        mutable TrafficColor currColor;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just noticed that my ViewController does not call init (See below) when
I just noticed that if I have an identity column in a table, when
I'm using protobuf-net r278 in C#, and I just noticed that if I have
I have noticed that the Windows Vista/7 dialogs look MUCH better than just a
I just started using Qt and noticed that all the example class definitions have
I just noticed something strange. If I have this XML: <level number=7 background=background_5> and
I just noticed the HashTable objects have a Contains and CotainsKey method, with same
I have just discovered a variable name that is misspelled. If it were hidden
I have noticed that some apps have a distinction between 'Invites from friends' vs
I noticed that I seemingly wasn't able to sort on relevance in a default

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.