aGrUM  0.18.1
a C++ library for (probabilistic) graphical models
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 
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 
98  template < typename T >
99  bool hasUniqueElts(std::vector< T > const& x);
100 
102 
103 } /* namespace std */
104 
105 namespace gum {
106 
109 
123  template < typename T1, typename T2 >
124  using forbidden_type =
125  typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type;
126 
130  struct NullStream: std::ostream {
131  NullStream() : std::ios(0), std::ostream(0) {}
132  };
133 
141  bool Memcmp(const void* const in_, const void* const out_, unsigned long size);
142 
146  void atexit__();
147 
152  template < typename T >
154  bool operator()(const T& t1, const T& t2) {
155  if (t1 == t2)
156  return false;
157  else if (t1 == 0)
158  return (std::abs(t2) > 1e-5);
159  else
160  return (std::abs(t2 - t1) / t1 > 1e-5);
161  }
162  };
163 
168  template < typename T >
169  struct AlmostDifferent< T* > {
170  bool operator()(const T* t1, const T* t2) { return (t1 != t2); }
171  };
172 
174 
175 } /* namespace gum */
176 
177 // Always include the template implementations
179 
180 #endif /* GUM_UTILS_H */
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
bool hasUniqueElts(std::vector< T > const &x)
STL namespace.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Definition: agrum.h:25
Indicate whether two elements are (almost) different or not.
Definition: utils_misc.h:153
bool operator()(const T *t1, const T *t2)
Definition: utils_misc.h:170
bool Memcmp(const void *const in_, const void *const out_, unsigned long size)
Cross-platform replacement for memcmp.
Definition: utils_misc.cpp:40
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:125
bool operator()(const T &t1, const T &t2)
Definition: utils_misc.h:154
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
void atexit__()
Used for debug purpose.
Definition: utils_misc.cpp:50
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Implements a stream with the same behaviour as /dev/null.
Definition: utils_misc.h:130