Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
mean_trait.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 20.07.2013 12:41:39 EDT
3 // File: mean_trait.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __MEAN_TRAIT_HEADER
12 #define __MEAN_TRAIT_HEADER
13 
14 #include "../ustd/type_traits.hpp"
15 
16 namespace util {
17  namespace detail {
18  template<typename T>
19  struct use_double_identifier {
20  static T t;
21 
22  static char check(T);
23  static double check(double);
24 
25  enum {value = (sizeof(check((t+t)/double(2))) == sizeof(double))};
26  };
27 
28  //------------------- full specialisation -------------------
29  template<>
30  struct use_double_identifier<double> {
31  enum {value = true}; //doesn't matter if true or false
32  };
33  }//end namespace detail
34 
35  //------------------- mean_trait -------------------
36  template<typename T>
37  struct mean_trait {
38  typedef
39  typename
41  , double
42  , T
43  >::type
45  };
46 }//end namespace util
47 
48 #endif //__MEAN_TRAIT_HEADER
Definition: type_traits.hpp:31
Definition: mean_trait.hpp:37
ustd::conditional< detail::use_double_identifier< T >::value, double, T >::type type
Definition: mean_trait.hpp:44