title: Boost ICL map that replaces values in intervals?
body: <p><a href="https://www.boost.org/doc/libs/1_69_0/libs/icl/doc/html/index.html" rel="nofollow noreferrer">Boost.ICL</a>'s <code>interval_map</code> has two kinds of behaviors: <code>+=</code> and <code>insert</code>. 
  Both are useful in different context. 
  The first adds up values in common intersections of two existing intervals. 
  The second simply introduces the new value only in <em>previously unassigned</em> intervals (in previously assigned intervals the value is kept). </p>
  
  <p>However I need a behavior that is subtly different, such that, in the example below instead of getting the undesired interval map <code>(1.,2.)-&gt;1 , (2.5,3.)-&gt;3, (3.,5.)-&gt;2</code> I get instead the desired <code>(1.,2.)-&gt;1 , (2.5,5.)-&gt;3</code>.</p>
  
  <p><strong>That is, that new inserted values replace old values? 
  How do I declare <code>interval_map</code> to get that <em>replacing</em> behavior?</strong></p>
  
  <pre><code>#include&lt;boost/icl/interval_map.hpp&gt;
  int main(){
      boost::icl::interval_map&lt;double, int&gt; joined_map;
      joined_map.insert( std::make_pair(
          boost::icl::interval&lt;double&gt;::open(1., 2.),
          1
      ));
      joined_map.insert( std::make_pair(
          boost::icl::interval&lt;double&gt;::open(3., 5.),
          2
      ));
      joined_map.insert( std::make_pair(
          boost::icl::interval&lt;double&gt;::open(2.5, 5.),
          3
      )); // this line doesn't replace the old value 2, it keeps it.
  }
  </code></pre>
  
  <p>Bonus: <strong>Is that what <code>boost::icl::map</code> is supposed to do? How do I use it?</strong></p>
  
  <hr>
  
  <p><strong>EDIT 1:</strong> This is a more explicit and simplified sample code using C++11</p>
  
  <pre><code>#include&lt;boost/icl/interval_map.hpp&gt;
  #include&lt;iostream&gt;
  
  namespace icl = boost::icl;
  using interval = icl::interval&lt;double&gt;;
  
  int main(){
      icl::interval_map&lt;double, int&gt; joined_map;
  
      joined_map.insert({interval::open(1., 2.), 1});
      joined_map.insert({interval::open(3., 5.), 2});
      joined_map.insert({interval::open(2.5, 5.), 3}); 
      // ^^^^ this line doesn't replace the old value 2! it keeps it.
      for(auto e: joined_map) std::cout &lt;&lt; e.first &lt;&lt;' '&lt;&lt; e.second &lt;&lt;'\n';
      // prints: (1,2) 1 \\ (2.5,3] 3 \\ (3,5) 2
      // desired: (1,2) 1 \\ (2.5,5] 3  // value 2 gone
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 2:</strong> <strong>Complete solution</strong> based on @JorgeBellon's answer:</p>
  
  <pre><code>#include&lt;boost/icl/interval_map.hpp&gt;
  #include&lt;iostream&gt;
  
  namespace icl = boost::icl;
  
  template &lt;class Type&gt;
  struct inplace_replace{// : icl::identity_based_inplace_combine&lt;Type&gt;{
      using first_argument_type = Type;
      void operator()(Type&amp; object, Type const&amp; operand) const{object = operand;}
  };
  
  using interval = icl::interval&lt;double&gt;;
  
  int main(){
  
      icl::interval_map&lt;
          double, int,
          icl::partial_enricher,   // Unmapped intervals have unkown value;
                                   // store identity values
          std::less             ,  // Comparator
          inplace_replace     //,  // Combination operator // IMPORTANT!!
      //  icl::inplace_erasure//,  // Extraction operator
      //  closed_interval&lt;unsigned, std::less&gt; // Interval type
      &gt; joined_map;
      joined_map.add({interval::open(1. , 2.), 1}); // or joined_map+=std::make_pair(...)
      joined_map.add({interval::open(3. , 5.), 2}); // IMPORTANT: USE add, NOT insert!!
      joined_map.add({interval::open(2.5, 5.), 3}); 
      // ^^^^ this line now replaces the old value 2
      for(auto e: joined_map) std::cout &lt;&lt; e.first &lt;&lt;' '&lt;&lt; e.second &lt;&lt;'\n';
      // prints: (1,2) 1 \\ (2.5,5] 3  // value 2 gone
  }
  </code></pre>