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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:18:05+00:00 2026-05-26T10:18:05+00:00

Using Boost 1_33_1, I get an error implying that my iterator is a const

  • 0

Using Boost 1_33_1, I get an error implying that my iterator is a const iterator (because it wont let me deref the result from find()).

$ g++ bmi_iter_tst.cpp 
bmi_iter_tst.cpp: In function ‘void tst(employee_set&)’:
bmi_iter_tst.cpp:32: error: invalid initialization of reference of type ‘employee&’ from expression of type ‘const employee’

I know I am not supposed to modify any of the key values, and I don’t, but I still need non-const acces sto modify other data in the container elements.

I know I have done this successfully elsewhere, I just can’t see what would make this const.

The code below is derived from the original boost::multi_index example

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>


using boost::multi_index_container;
using namespace boost::multi_index;

struct employee
{
  int         id;
  int         tst;

  employee(int id_):id(id_), tst(0){}
};


struct id{};


typedef multi_index_container<
  employee,
  indexed_by<
    ordered_unique<
      tag<id>,  BOOST_MULTI_INDEX_MEMBER(employee,int,id)> >
> employee_set;


void tst(employee_set& s)
{
  employee_set::index_iterator<id>::type it = s.get<id>().find(11);
  employee& eref = *it;

  eref.tst++;
}
  • 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-26T10:18:05+00:00Added an answer on May 26, 2026 at 10:18 am

    From the MultiIndex docs on random access indices:

    As usual in Boost.MultiIndex, elements of random access indices are
    immutable and can only be modified through member functions replace
    and modify. This precludes the usage of many mutating algorithms that
    are nonetheless applicable to std::vectors.

    This applies to ordered indexes as well.

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

Sidebar

Related Questions

I'm using CentOS 5.4 x86_64 and Boost 1.42.0 on a cluster that uses Open-MPI
Using boost::program_options, I can not get my own option type to compile when it
I am using the timed_wait from boost C++ library and I am getting a
I'm trying setup a subset of boost and get it properly compiled using bjam,
I am getting compilation error with g++4.6 and boost 1.42 when using boost::make_shared<T>(...) ,
I'm using Boost 1.45 ASIO to handle some socket connections in an application that
I'm using a fairly simple boost::asio set-up, where I call io_service.run() from the main
I'm using boost for several C++ projects. I recently made a upgrade (1.33.1 to
I have just started using Boost 1.36. These libraries would be very useful in
I am using Ubuntu 9.10 beta, whose repositories contain boost 1.38. I would like

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.