[Boost-bugs] [Boost C++ Libraries] #11001: insert_range lacks support for extensible associative sequences

Subject: [Boost-bugs] [Boost C++ Libraries] #11001: insert_range lacks support for extensible associative sequences
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-02-09 00:10:47


#11001: insert_range lacks support for extensible associative sequences
--------------------------------------------+-----------------------
 Reporter: brunocodutra@… | Owner: agurtovoy
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: mpl
  Version: Boost 1.57.0 | Severity: Problem
 Keywords: insert_range, map, associative |
--------------------------------------------+-----------------------
 According to reference, the insert_range should work for any Extensible
 sequence or Extensible Associative sequence, but the following fails to
 compile.

 {{{
 #include <boost/mpl/pair.hpp>
 #include <boost/mpl/map.hpp>
 #include <boost/mpl/insert_range.hpp>
 #include <boost/mpl/end.hpp>
 #include <boost/mpl/equal.hpp>

 typedef boost::mpl::map<boost::mpl::pair<int, int>, boost::mpl::pair<void,
 void> > myMap;
 typedef boost::mpl::insert_range<boost::mpl::map<>,
 boost::mpl::end<boost::mpl::map<> >::type, myMap>::type copyOfMyMap;
 BOOST_MPL_ASSERT((boost::mpl::equal<myMap, copyOfMyMap>));

 int main()
 {
     return 0;
 }
 }}}

 I tracked the issue down to the definition of insert_range_impl, whose
 default implementation assumes a front_inserter is defined for the given
 sequence, but neither Extensible nor every Extensible Associative
 sequences are required to also be a Front Extensible sequence:


 {{{
 reverse_copy<
     joint_view<
         iterator_range<typename begin<Sequence>::type,Pos>
     , joint_view<
             Range
         , iterator_range<Pos,typename end<Sequence>::type>
>
>
 , front_inserter< typename clear<Sequence>::type >
>
 }}}


 I found the fix to be implementing insert_range_impl by means of insert,
 which is defined for every Extensible sequence, using fold to iterate:

 {{{
 fold<
     joint_view<
         iterator_range<typename begin<Sequence>::type,Pos>
     , joint_view<
             Range
         , iterator_range<Pos,typename end<Sequence>::type>
>
>
 , typename clear<Sequence>::type
 , insert<_1, end<_1>, _2>
>
 }}}

 I'll file a pull request for this fix, any comments are welcome.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11001>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC