CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
CASM_TMP.hh
Go to the documentation of this file.
1 #ifndef CASM_TMP_HH
2 #define CASM_TMP_HH
3 
4 #include <type_traits>
5 #include <cassert>
6 
8 
9 namespace CASM {
10  namespace CASM_TMP {
11 
12  template <typename T>
13  struct traits {};
14 
15  // ---------------------
16 
18  template<typename...Args>
19  void ignore_returnvalues(Args &&...) {}
20 
21  // ---------------------
22 
24  template<typename... Ts>
25  struct make_void {
26  typedef void type;
27  };
28 
30  template<typename... Ts>
31  using void_t = typename make_void<Ts...>::type;
32 
36  template <typename T, typename = void>
37  struct is_iterator : std::false_type { };
38 
42  template <typename T>
43  struct is_iterator < T,
44  void_t < decltype(++std::declval<T &>()),
45  decltype(*std::declval<T &>()),
46  decltype(std::declval<T &>() == std::declval<T &>()) > >
47  : std::true_type { };
48 
52  template<typename T>
53  using enable_if_iterator = std::enable_if<is_iterator<T>::type::value, void>;
54 
58  template<typename T, typename V>
59  using enable_if_iterator_of =
60  std::enable_if < is_iterator<T>::type::value &&
61  std::is_same<typename std::iterator_traits<T>::value_type, V>::type::value, void >;
62 
63  // --------------------
64 
65  // Definitions for IfIntegralTol
66  template <typename tol_type, bool IsIntegral>
67  struct IfIntegralTol;
68 
69  template <typename tol_type>
70  struct IfIntegralTol<tol_type, true> {
72  IfIntegralTol(tol_type) {};
73  tol_type tol() const {
74  return 0;
75  }
76  };
77 
78  template <typename tol_type>
79  struct IfIntegralTol<tol_type, false> {
80  IfIntegralTol(tol_type _tol) : m_tol(_tol) {};
81  tol_type tol() {
82  return m_tol;
83  }
84  private:
85  tol_type m_tol;
86  };
87 
88  template<typename T>
90  // End of IfIntegralTol
91 
92  template<bool IsConst, typename T>
93  using ConstSwitch = typename std::conditional<IsConst, const T, T>::type;
94 
95 
96  // Definitions for MuchLessThan
97  template<typename value_type>
100  IntegralLessThan(value_type) {};
101  bool operator()(const value_type &A, const value_type &B) const {
102  return A < B;
103  };
104  };
105 
106  template<typename value_type>
108  FloatingPointLessThan(value_type _tol = TOL) : m_tol(_tol) {};
109  bool operator()(const value_type &A, const value_type &B) const {
110  return A + m_tol < B;
111  };
112  private:
113  value_type m_tol;
114  };
115 
116  template<typename T>
117  using MuchLessThan = typename std::conditional<boost::is_integral<T>::value, IntegralLessThan<T>, FloatingPointLessThan<T> >::type;
118  // End of MuchLessThan
119 
120 
122  template < typename Container,
123  typename _value_type = typename Container::value_type,
124  typename _size_type = typename Container::size_type >
125  struct BracketAccess {
126 
127  typedef _value_type value_type;
128  typedef _size_type size_type;
129 
132  return *this;
133  };
134 
136  value_type &operator()(Container &container, size_type index) const {
137  return container[index];
138  }
139 
141  const value_type &operator()(const Container &container, size_type index) const {
142  return container[index];
143  }
144 
146  value_type &operator()(Container &container, size_type i, size_type j) const {
147  return container[i][j];
148  }
149 
151  const value_type &operator()(const Container &container, size_type i, size_type j) const {
152  return container[i][j];
153  }
154 
156  static value_type &at(Container &container, size_type index) {
157  return container[index];
158  }
159 
161  static const value_type &at(const Container &container, size_type index) {
162  return container[index];
163  }
164 
166  static value_type &at(Container &container, size_type i, size_type j) {
167  return container[i][j];
168  }
169 
171  static const value_type &at(const Container &container, size_type i, size_type j) {
172  return container[i][j];
173  }
174  };
175 
177  template < typename Container,
178  typename _value_type = typename Container::value_type,
179  typename _size_type = typename Container::size_type >
181 
182  typedef _value_type value_type;
183  typedef _size_type size_type;
184 
187  return *this;
188  };
189 
190 
192  value_type &operator()(Container &container, size_type index) const {
193  return container(index);
194  }
195 
197  const value_type &operator()(const Container &container, size_type index) const {
198  return container(index);
199  }
200 
202  value_type &operator()(Container &container, size_type i, size_type j) const {
203  return container(i, j);
204  }
205 
207  const value_type &operator()(const Container &container, size_type i, size_type j) const {
208  return container(i, j);
209  }
210 
212  static value_type &at(Container &container, size_type index) {
213  return container(index);
214  }
215 
217  static const value_type &at(const Container &container, size_type index) {
218  return container(index);
219  }
220 
222  static value_type &at(Container &container, size_type i, size_type j) {
223  return container(i, j);
224  }
225 
227  static const value_type &at(const Container &container, size_type i, size_type j) {
228  return container(i, j);
229  }
230 
231  };
232 
233 
234  }
235 
236 }
237 
238 #endif
static const value_type & at(const Container &container, size_type index)
Identical to 'return container[index];'.
Definition: CASM_TMP.hh:161
value_type & operator()(Container &container, size_type index) const
Identical to 'return container(index);'.
Definition: CASM_TMP.hh:192
typename std::conditional< IsConst, const T, T >::type ConstSwitch
Definition: CASM_TMP.hh:93
bool operator()(const value_type &A, const value_type &B) const
Definition: CASM_TMP.hh:101
Alias for void, to help SFINAE work.
Definition: CASM_TMP.hh:25
value_type & operator()(Container &container, size_type i, size_type j) const
Identical to 'return container(index);'.
Definition: CASM_TMP.hh:202
const value_type & operator()(const Container &container, size_type index) const
Identical to 'return container(index);'.
Definition: CASM_TMP.hh:197
value_type & operator()(Container &container, size_type i, size_type j) const
Identical to 'return container[i][j];'.
Definition: CASM_TMP.hh:146
static const value_type & at(const Container &container, size_type index)
Identical to 'return container(index);'.
Definition: CASM_TMP.hh:217
BracketAccess & operator=(const BracketAccess &)
Definition: CASM_TMP.hh:131
typename make_void< Ts...>::type void_t
Alias for void, to help SFINAE work.
Definition: CASM_TMP.hh:31
ParenthesesAccess & operator=(const ParenthesesAccess &)
Definition: CASM_TMP.hh:186
Main CASM namespace.
Definition: complete.cpp:8
const double TOL
std::enable_if< is_iterator< T >::type::value &&std::is_same< typename std::iterator_traits< T >::value_type, V >::type::value, void > enable_if_iterator_of
Template alias to enable a template function via SFINAE for an iterator with value_type V...
Definition: CASM_TMP.hh:61
static value_type & at(Container &container, size_type index)
Identical to 'return container(index);'.
Definition: CASM_TMP.hh:212
Base type inherits from std::false_type if T is not iterator.
Definition: CASM_TMP.hh:37
Helper Functor for Counter container access using operator()
Definition: CASM_TMP.hh:180
static value_type & at(Container &container, size_type i, size_type j)
Identical to 'return container[i][j];'.
Definition: CASM_TMP.hh:166
static const value_type & at(const Container &container, size_type i, size_type j)
Identical to 'return container(i,j);'.
Definition: CASM_TMP.hh:227
static value_type & at(Container &container, size_type i, size_type j)
Identical to 'return container(i,j);'.
Definition: CASM_TMP.hh:222
const value_type & operator()(const Container &container, size_type i, size_type j) const
Identical to 'return container(index);'.
Definition: CASM_TMP.hh:207
static const value_type & at(const Container &container, size_type i, size_type j)
Identical to 'return container[i][j];'.
Definition: CASM_TMP.hh:171
static value_type & at(Container &container, size_type index)
Identical to 'return container[index];'.
Definition: CASM_TMP.hh:156
FloatingPointLessThan(value_type _tol=TOL)
Definition: CASM_TMP.hh:108
const value_type & operator()(const Container &container, size_type index) const
Identical to 'return container[index];'.
Definition: CASM_TMP.hh:141
const value_type & operator()(const Container &container, size_type i, size_type j) const
Identical to 'return container[i][j];'.
Definition: CASM_TMP.hh:151
Helper Functor for Counter container access using operator[].
Definition: CASM_TMP.hh:125
std::enable_if< is_iterator< T >::type::value, void > enable_if_iterator
Template alias to enable a template function via SFINAE for any iterator.
Definition: CASM_TMP.hh:53
void ignore_returnvalues(Args &&...)
Enables calling a function on each argument in a parameter pack.
Definition: CASM_TMP.hh:19
value_type & operator()(Container &container, size_type index) const
Identical to 'return container[index];'.
Definition: CASM_TMP.hh:136
typename std::conditional< boost::is_integral< T >::value, IntegralLessThan< T >, FloatingPointLessThan< T > >::type MuchLessThan
Definition: CASM_TMP.hh:117
bool operator()(const value_type &A, const value_type &B) const
Definition: CASM_TMP.hh:109