Boost logo

Boost :

Subject: [boost] [multi_index] scalar insert interface
From: Maxim Yegorushkin (maxim.yegorushkin_at_[hidden])
Date: 2010-11-05 12:59:16

Hey guys,

In ordered_index there are two scalar insert overloads:

   std::pair<iterator,bool> insert(const value_type& x);
   iterator insert(iterator position,const value_type& x);

The second version is lacking the bool result, which is sometimes
required. In my source code of boost-1_42 I patched the second version
like this:

==== .../ordered_index.hpp#2 (text) ====

@@ -97,6 +99,16 @@
  struct ordered_unique_tag{};
  struct ordered_non_unique_tag{};

+template<class T, class U>
+struct auto_cast_pair : std::pair<T, U>
+ typedef std::pair<T, U> base_pair;
+ auto_cast_pair(base_pair const& b) : base_pair(b) {}
+ using base_pair::operator=;
+ operator T&() { return this->first; }
+ operator T const&() const { return this->first; }
    typename KeyFromValue,typename Compare,
    typename SuperMeta,typename TagList,typename Category
@@ -274,14 +286,14 @@
      return std::pair<iterator,bool>(make_iterator(p.first),p.second);

- iterator insert(iterator position,value_param_type x)
+ auto_cast_pair<iterator,bool> insert(iterator
position,value_param_type x)
      std::pair<final_node_type*,bool> p=this->final_insert_(
- return make_iterator(p.first);
+ return std::pair<iterator,bool>(make_iterator(p.first),p.second);

    template<typename InputIterator>

Now it automatically figures which return value one wants. Just an idea.


Boost list run by bdawes at, gregod at, cpdaniel at, john at