Changeset 2159


Ignore:
Timestamp:
Jan 20, 2010, 12:48:24 AM (12 years ago)
Author:
Peter
Message:

fixes #586 and refs #587
extend test of Averager and AveragerWeighted?. Document requirement in iterators.

weighted_iterator_traits<T>::type now returns weighted if T is
convertible to DataWeight? (refs #604).

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/averager_test.cc

    r2121 r2159  
    3030#include "yat/statistics/AveragerWeighted.h"
    3131#include "yat/utility/Vector.h"
     32
     33#include <boost/concept_archetype.hpp>
    3234
    3335#include <cmath>
     
    359361    suite.err() << "error for x_averager():\t" << std::endl;
    360362  }
     363
     364  // compile tests should not be run
     365  if (false) {
     366    Averager averager;
     367    add(averager, boost::input_iterator_archetype<double>(),
     368        boost::input_iterator_archetype<double>());
     369    AveragerWeighted averagerw;
     370    using utility::DataWeight;
     371    typedef boost::input_iterator_archetype<DataWeight> Iter;
     372    Iter iter;
     373    utility::iterator_traits<Iter> traits;
     374    //traits.weight(iter);
     375    //    add(averagerw, boost::input_iterator_archetype<DataWeight>(),
     376    //  boost::input_iterator_archetype<DataWeight>());
     377  }
     378
    361379  return ok;
    362380}
  • trunk/test/iterator_test.cc

    r2151 r2159  
    3030#include "yat/utility/Container2DIterator.h"
    3131#include "yat/utility/DataWeight.h"
     32#include "yat/utility/DataWeightProxy.h"
    3233#include "yat/utility/DataIterator.h"
    3334#include "yat/utility/Matrix.h"
     
    297298  double w = traits.weight(vec.begin());
    298299  suite.add(suite.equal(w, 1.0));
     300  utility::iterator_traits<utility::DataWeight*>().weight(&vec[0]);
     301
     302  double* trivial_iter = new double(1.0);
     303  utility::DataWeightProxy<double*, double*> dwp(trivial_iter,trivial_iter);
     304  typedef utility::DataWeightProxy<double*, double*> Proxy;
     305  //utility::iterator_traits<Proxy*> traits2;
     306  //traits2.weight(&dwp);
     307  delete trivial_iter;
    299308}
    300309
  • trunk/yat/statistics/Averager.h

    r2119 r2159  
    2727
    2828#include "yat/utility/iterator_traits.h"
     29
     30#include <boost/concept_check.hpp>
    2931
    3032#include <cmath>
     
    186188     \relates Averager
    187189   */
    188   template <typename Iter>
    189   void add(Averager& a, Iter first, Iter last)
     190  template <typename InputIterator>
     191  void add(Averager& a, InputIterator first, InputIterator last)
    190192  {
     193    BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
    191194    utility::check_iterator_is_unweighted(first);
    192195    for ( ; first != last; ++first)
  • trunk/yat/statistics/AveragerWeighted.h

    r2119 r2159  
    216216     \relates AveragerWeighted
    217217   */
    218   template <typename Iter>
    219   void add(AveragerWeighted& a, Iter first, Iter last)
     218  template <typename InputIter>
     219  void add(AveragerWeighted& a, InputIter first, InputIter last)
    220220  {
     221    utility::iterator_traits<InputIter> traits;
    221222    for ( ; first != last; ++first)
    222       a.add(utility::iterator_traits<Iter>().data(first),
    223             utility::iterator_traits<Iter>().weight(first));
     223      a.add(traits.data(first), traits.weight(first));
    224224  }
    225225
  • trunk/yat/utility/iterator_traits.h

    r2151 r2159  
    2525
    2626#include "DataWeight.h"
     27
     28#include <boost/type_traits/is_convertible.hpp>
     29#include <boost/utility/enable_if.hpp>
    2730
    2831#include <iterator>
     
    5356     used in weighted_iterator_traits
    5457  */
    55   template <typename T>
     58  template <typename T, typename Enable = void>
    5659  struct weighted_iterator_traits_detail {
    5760    /**
     
    6669      specialization for iterators with value type DataWeight
    6770  */
    68   template <>
    69   struct weighted_iterator_traits_detail<DataWeight> {
     71  template <typename T>
     72  struct weighted_iterator_traits_detail<T, typename boost::enable_if<typename boost::is_convertible<T, DataWeight>::type>::type > {
    7073    /**
    7174       Iterators with value type DataWeight is weighted
     
    7376    typedef weighted_iterator_tag type;
    7477  }; 
     78
    7579} // namespace detail
    7680
Note: See TracChangeset for help on using the changeset viewer.