Changeset 2857


Ignore:
Timestamp:
Sep 28, 2012, 1:17:17 AM (9 years ago)
Author:
Peter
Message:

closes #726

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility.cc

    r2673 r2857  
    44  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
    55  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    6   Copyright (C) 2009, 2010, 2011 Peter Johansson
     6  Copyright (C) 2009, 2010, 2011, 2012 Peter Johansson
    77
    88  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    383383    std::multimap<std::string, size_t, std::greater<std::string> > m4;
    384384    utility::inverse(start, end, m4);
     385
     386    std::map<std::string, size_t> unique_map;
     387    utility::inverse(start, end, unique_map);
    385388  }
    386389}
  • trunk/yat/utility/stl_utility.h

    r2731 r2857  
    432432
    433433  /**
     434     Create a map mapping from values in range [first, last) to the
     435     distance from first.
     436
     437     Post-condition: m[first[i]] == i (for all i that correspond to a
     438     unique element). For non-unique element behaviour is undefined.
     439
     440     Requirement: InputIterator's value type is assignable to Key
     441
     442     \since New in yat 0.10
     443   */
     444  template<typename InputIterator, typename Key, typename Comp>
     445  void inverse(InputIterator first, InputIterator last,
     446               std::map<Key, size_t, Comp >& m)
     447  {
     448    BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
     449    BOOST_CONCEPT_ASSERT((boost::Convertible<typename std::iterator_traits<InputIterator>::value_type, Key>));
     450    m.clear();
     451    for (size_t i=0; first!=last; ++i, ++first)
     452      m[*first] = i;
     453  }
     454
     455  /**
    434456     \brief Functor that behaves like std::less with the exception
    435457     that it treates NaN as a number larger than infinity.
Note: See TracChangeset for help on using the changeset viewer.