source: trunk/yat/statistics/averager_traits.h

Last change on this file was 3550, checked in by Peter, 5 years ago

Update copyright years. Happy New Year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_yat_utility_averager_traits_
2#define _theplu_yat_utility_averager_traits_
3
4// $Id: averager_traits.h 3550 2017-01-03 05:41:02Z peter $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2016 Peter Johansson
9
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include "Averager.h"
27#include "AveragerWeighted.h"
28#include "AveragerPair.h"
29#include "AveragerPairWeighted.h"
30#include "yat/utility/iterator_traits.h"
31
32namespace theplu {
33namespace yat {
34namespace statistics {
35
36  /**
37     MetaFunction returning weighted or unweighted Averager.
38   */
39  template <typename T>
40  struct averager_traits{};
41
42  /**
43     Specialization for unweighted_tag return (unweighted) Averager
44  */
45  template <>
46  struct averager_traits<utility::unweighted_iterator_tag>
47  {
48    /**
49        Metafunction returning Averager
50    */
51    typedef Averager type;
52    /**
53        Metafunction returning AveragerPair
54    */
55    typedef AveragerPair pair_type;
56  };
57
58  /**
59     Specialization for weighted_tag return AveragerWeighted
60  */
61  template <>
62  struct averager_traits<utility::weighted_iterator_tag>
63  {
64    /**
65       Metafunction returning AveragerWeighted
66     */
67    typedef AveragerWeighted type;
68    /**
69       Metafunction returning AveragerPairWeighted
70    */
71    typedef AveragerPairWeighted pair_type;
72  };
73
74  /**
75      Convenience wrapper around averager_traits
76      \see weighted_iterator_traits                                         \
77  */
78  template <typename Iterator>
79  struct averager
80  {
81  /**
82      Convenience Metafunction taking iterator as argument and return
83      either Averager (if iterator is unweighted) or AveragerWeighted
84      (if iterator is unweighted)
85  */
86    typedef typename averager_traits<typename utility::weighted_iterator_traits<Iterator>::type>::type type;
87  };
88
89  /**
90      Convenience wrapper around averager_traits
91      \see weighted_iterator_traits                                         \
92  */
93  template <typename Iterator1, typename Iterator2>
94  struct averager_pair
95  {
96  /**
97      Convenience Metafunction taking two iterators as argument and
98      return either AveragerPair (if both iterators are unweighted) or
99      AveragerPairWeighted otherwise.
100  */
101    typedef typename
102      averager_traits<
103        typename utility::weighted_if_any2<Iterator1, Iterator2>::type
104      >::pair_type type;
105  };
106
107}}} // of namespace statistics, yat, and theplu
108
109#endif
Note: See TracBrowser for help on using the repository browser.