Changeset 2068


Ignore:
Timestamp:
Sep 17, 2009, 11:12:21 PM (11 years ago)
Author:
Peter
Message:

fixes #562

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r2065 r2068  
    55Version 0.6 (released DATE)
    66
     7  - pair_first_iterator and pair_second_iterator now work with
     8    const_iterator (ticket:562)
    79  - Passing by const& in KolmogorovSmirnov::Element::operator< (r2064)
    810  - classes OptionInFile and OptionOutFile are deprecated (ticket:521)
  • trunk/test/iterator_test.cc

    r1877 r2068  
    4545#include <fstream>
    4646#include <iterator>
     47#include <map>
     48#include <set>
    4749#include <string>
    4850#include <vector>
     
    5961
    6062void test_boost_util(test::Suite&);
     63void test_pair_second_iterator(test::Suite&);
    6164
    6265void test_stride_iterator(test::Suite& suite);
     
    7275  old_main(suite);
    7376  test_boost_util(suite);
     77  test_pair_second_iterator(suite);
    7478  test_weighted_iterator(suite);
    7579  return suite.return_value();
     
    360364}
    361365
     366void test_pair_second_iterator(test::Suite& suite)
     367{
     368  typedef std::map<std::string, std::string> C;
     369  C person2color;
     370  person2color["me"] = "yellow";
     371  person2color["you"] = "orange";
     372
     373  C::const_iterator cbegin = person2color.begin();
     374  C::const_iterator cend = person2color.end();
     375
     376  std::set<std::string> colors;
     377  colors.insert(utility::pair_second_iterator(cbegin),
     378               utility::pair_second_iterator(cend));
     379
     380  suite.test_bidirectional_iterator(utility::pair_second_iterator(cbegin));
     381  suite.test_bidirectional_iterator(utility::pair_first_iterator(cbegin));
     382}
  • trunk/yat/utility/stl_utility.h

    r2010 r2068  
    3939#include <boost/iterator/transform_iterator.hpp>
    4040#include <boost/mpl/if.hpp>
     41#include <boost/type_traits/add_const.hpp>
    4142#include <boost/type_traits/is_const.hpp>
    42 #include <boost/type_traits/add_const.hpp>
     43#include <boost/type_traits/remove_reference.hpp>
    4344
    4445#include <algorithm>
     
    432433  template<class Iter>
    433434  boost::transform_iterator<
    434     PairFirst<typename std::iterator_traits<Iter>::value_type>,
     435    PairFirst<typename boost::remove_reference<
     436                 typename std::iterator_traits<Iter>::reference
     437                 >::type>,
    435438    Iter> pair_first_iterator(Iter i)
    436439  {
    437     typedef PairFirst<typename std::iterator_traits<Iter>::value_type> PF;
     440    // We are going via ::reference in order to remain const info;
     441    // ::value_type does not contain const information.
     442    typedef typename std::iterator_traits<Iter>::reference ref_type;
     443    typedef typename boost::remove_reference<ref_type>::type val_type;
     444    typedef PairFirst<val_type> PF;
    438445    return boost::transform_iterator<PF, Iter>(i, PF());
    439446  }
     
    457464  template<class Iter>
    458465  boost::transform_iterator<
    459     PairSecond<typename std::iterator_traits<Iter>::value_type>,
     466    PairSecond<typename boost::remove_reference<
     467                 typename std::iterator_traits<Iter>::reference
     468                 >::type>,
    460469    Iter> pair_second_iterator(Iter i)
    461470  {
    462     typedef PairSecond<typename std::iterator_traits<Iter>::value_type> PF;
    463     return boost::transform_iterator<PF, Iter>(i, PF());
     471    // We are going via ::reference in order to remain const info;
     472    // ::value_type does not contain const information.
     473    typedef typename std::iterator_traits<Iter>::reference ref_type;
     474    typedef typename boost::remove_reference<ref_type>::type val_type;
     475    typedef PairSecond<val_type> PS;
     476    return boost::transform_iterator<PS, Iter>(i, PS());
    464477  }
    465478
Note: See TracChangeset for help on using the changeset viewer.