aGrUM  0.16.0
utils_misc.h
Go to the documentation of this file.
1 
30 #ifndef GUM_UTILS_H
31 #define GUM_UTILS_H
32 
33 #include <cstdlib>
34 #include <iostream>
35 #include <numeric>
36 #include <utility>
37 #include <vector>
38 #include <tuple>
39 #include <string>
40 #include <type_traits>
41 
42 
43 #ifdef GUM_DEBUG_MODE
44 # define GUM_CAST dynamic_cast
45 #else
46 # define GUM_CAST static_cast
47 #endif // GUM_DEBUG_MODE
48 
49 #include <agrum/agrum.h>
50 
51 #include <agrum/core/utils_dir.h>
54 
55 namespace std {
56 
59 
68  template < typename T1, typename T2 >
69  ostream& operator<<(ostream& stream, const pair< T1, T2 >& val);
70 
78  template < typename T0, typename... T >
79  std::ostream& operator<<(std::ostream& os, const std::tuple< T0, T... >& t);
80 
81 
89  template < typename T >
90  ostream& operator<<(ostream& stream, const vector< T >& val);
91 
100  template < typename T >
101  bool hasUniqueElts(std::vector< T > const& x);
102 
104 
105 } /* namespace std */
106 
107 namespace gum {
108 
111 
125  template < typename T1, typename T2 >
126  using forbidden_type =
127  typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type;
128 
132  struct NullStream : std::ostream {
133  NullStream() : std::ios(0), std::ostream(0) {}
134  };
135 
143  bool Memcmp(const void* const _in, const void* const _out, unsigned long size);
144 
148  void __atexit();
149 
154  template < typename T >
156  bool operator()(const T& t1, const T& t2) {
157  if (t1 == t2)
158  return false;
159  else if (t1 == 0)
160  return (std::abs(t2) > 1e-5);
161  else
162  return (std::abs(t2 - t1) / t1 > 1e-5);
163  }
164  };
165 
170  template < typename T >
171  struct AlmostDifferent< T* > {
172  bool operator()(const T* t1, const T* t2) { return (t1 != t2); }
173  };
174 
176 
177 } /* namespace gum */
178 
179 // Always include the template implementations
181 
182 #endif /* GUM_UTILS_H */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool hasUniqueElts(std::vector< T > const &x)
STL namespace.
void __atexit()
Used for debug purpose.
Definition: utils_misc.cpp:50
bool Memcmp(const void *const _in, const void *const _out, unsigned long size)
Cross-platform replacement for memcmp.
Definition: utils_misc.cpp:40
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Indicate whether two elements are (almost) different or not.
Definition: utils_misc.h:155
bool operator()(const T *t1, const T *t2)
Definition: utils_misc.h:172
ostream & operator<<(ostream &stream, const vector< T > &val)
&#39;std::cout<<&#39; operator for vectors.
typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type forbidden_type
Forbidden_type<T1,T2> return the "int" type if T1 and T2 are of the same type, else nothing...
Definition: utils_misc.h:127
bool operator()(const T &t1, const T &t2)
Definition: utils_misc.h:156
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Implements a stream with the same behaviour as /dev/null.
Definition: utils_misc.h:132