aimstil  5.0.5
sparse_vector_policies.h
Go to the documentation of this file.
1 #ifndef TIL_SPARSE_VECTOR_POLICIES_H
2 #define TIL_SPARSE_VECTOR_POLICIES_H
3 
11 
12 #include "til/miscTools.h"
13 
14 namespace til { namespace policy
15 {
16 
18  template < typename T >
20  {
21  struct Exception : public std::runtime_error
22  { Exception(const std::string & msg) : std::runtime_error(msg) {} };
23 
25  T operator()(std::size_t) const { return T(); }
26 
27  void setValue(const T & value)
28  {
29  if (value != T())
30  {
31  std::cerr << "Can't change baseline value to " << value << std::endl;
32  throw Exception("Can't change baseline value");
33  }
34  }
35  };
36 
37 
38  template < typename T >
40  {
41  struct Exception : public std::runtime_error
42  { Exception(const std::string & msg) : std::runtime_error(msg) {} };
43 
44 
45  SVBaseline_Value() : m_value() {}
46  explicit SVBaseline_Value(const T & value) : m_value(value) {}
47 
49  T operator()(std::size_t) const { return m_value; }
50 
51  void setValue(const T & value)
52  {
53  m_value = value;
54  }
55 
57  };
58 
59 
60 }} // namespace til::policy
61 
62 #endif
63 
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
Take the default value of type T as the baseline value of a sparse vector.
T operator()(std::size_t) const
Get default value at current position.
T operator()(std::size_t) const
Get default value at current position.