eos icon indicating copy to clipboard operation
eos copied to clipboard

multi_index::rbegin, rend, begin, and end all return const iterators

Open PhillipHamnett opened this issue 8 years ago • 2 comments

They should return non-const iterators.

PhillipHamnett avatar Nov 27 '18 15:11 PhillipHamnett

Why do you think of that? You can access data by iterator with *() operator, but it doesn't mean you can modify table data with iterator directly. eosio::multi_index allow user to modify table data only when const iterator is passed as the first argument of modify().

conr2d avatar Nov 27 '18 17:11 conr2d

conr2d is correct. Only modify() is allowed to change rows. As you can see reading the method, modifying a row is nontrivial. To maintain the integrity of the indices, modify() must do a lot of work.

For consistency with typical usage of STL containers, you may use cbegin() etc. in your code, which are provided as well. The multi_index impersonation of STL containers is imperfect, but many STL algorithms will still work. The multi_index const_iterator is a bidirectional iterator, and carries that STL tag. For algorithms which write, you just have to carefully construct predicates to use modify().

jgiszczak avatar Nov 27 '18 19:11 jgiszczak