Ticket #4623 (closed Patches: invalid)

Opened 7 years ago

Last modified 7 years ago

at() member function to ordered_index/hashed_index

Reported by: Akira Takahashi <faithandbrave@…> Owned by: joaquin
Milestone: To Be Determined Component: multi_index
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:


ordered_index/hashed_index don't have operator[]() and at() member functions, those are inconsistent with std::map/boost::unordered_map. For this reason find() member function need to be used to access an element in ordered_index/hashed_index. It's annoying.

To solve this issue, I propose to implement at() member function to ordered_index/hashed_index. operator[]() should not be added because it will conflict with random_access. (patches to implement my proposal are attached below)

According to the design of MultiIndex? library, I've only implemented const version of at() member function and left non-const version of at(), which allows destructive change, unimplemented.

Although I think optional_at() member function which will report an error by boost::optional looks useful, I haven't included it in this proposal since error handling policy of MultiIndex? library with using boost::optional is undefined.


ordered_index.patch (814 bytes) - added by Akira Takahashi <faithandbrave@…> 7 years ago.
hashed_index.patch (773 bytes) - added by Akira Takahashi <faithandbrave@…> 7 years ago.
test_at.cpp (1.2 KB) - added by Akira Takahashi <faithandbrave@…> 7 years ago.
test code

Change History

Changed 7 years ago by Akira Takahashi <faithandbrave@…>

Changed 7 years ago by Akira Takahashi <faithandbrave@…>

Changed 7 years ago by Akira Takahashi <faithandbrave@…>

test code

comment:1 Changed 7 years ago by joaquin

Hello Akira,

ordered indices do not implement at() because their interface is modelled after that of std::set, not std::map. Your proposed implementation of an at() member function is not consistent with the one std::map provides:

template<class Key, class T,...>
class map{
  const T& at(const key_type& x) const;

Note that std::map::at returns a reference to T, not a reference to value_type as you're doing. Translating this to the Boost.MultiIndex? realm would imply returning a reference to the part of value_type that is not the key, which in general is not possible (it is possible in the case of std::map because value_type is std::par<const Key,T> and hence the key is nicely separated from the rest of the value).

Closing this as a non-problem.

comment:2 Changed 7 years ago by joaquin

  • Status changed from new to closed
  • Resolution set to invalid

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.