Changeset 1373


Ignore:
Timestamp:
Jul 16, 2008, 6:12:27 PM (13 years ago)
Author:
Peter
Message:

refs #391 generalized default implementation of iterator_traits by templatizing return types. Also added a default constructor that checks that the class only compiles with unweighted iterators (weighted iterators should have their specialized classes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/iterator_traits.h

    r1365 r1373  
    2525  02111-1307, USA.
    2626*/
     27
     28#include <iterator>
    2729
    2830namespace theplu {
     
    139141  template <class Iter>
    140142  struct iterator_traits {
    141     // Peter, perhaps these should be templatized, but for now return
    142     // type double is hard coded.
     143    /**
     144       \brief Default constructor
     145
     146       Does nothing but check that Iter is unweighted (at compile time).
     147     */
     148    iterator_traits(void)
     149    {
     150      check_iterator_is_unweighted(typename weighted_iterator_traits<Iter>::type()); }
     151
     152    /**
     153       An unweighted iterator has data_reference = reference
     154     */
     155    typedef typename std::iterator_traits<Iter>::reference data_reference;
     156
     157    /**
     158       An unweighted iterator has a weight = 1.0 and since this is a
     159       temporary it is returned by value and weight_reference is double
     160     */
     161    typedef double weight_reference;
     162
    143163    /**
    144164       \return data that is *iter
    145165    */
    146     double data(Iter iter) const
     166    data_reference data(Iter iter) const
    147167    { check_iterator_is_unweighted(iter); return *iter; }
    148168
     
    150170       \return 1.0
    151171    */
    152     double weight(Iter iter) const
     172    weight_reference weight(Iter iter) const
    153173    { check_iterator_is_unweighted(iter); return 1.0; }
    154174
Note: See TracChangeset for help on using the changeset viewer.