Fleet  0.0.9
Inference in the LOT
Object.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include<iostream>
5 #include<tuple>
6 
7 #include "Random.h"
8 #include "Strings.h"
9 
19 template<typename... feature_t> // template of the features
20 struct Object {
21  std::tuple<feature_t...> feature;
22 
23  // Well.. this is the craziest hack. Down below we need to define operator<<
24  // and that complains when given feature_t={} because it redefines this constructor
25  // however, there is no problem if we define this with a *default* parameter
26  // (which allows it ot be called as Object(), but doesn't seem to clash with the
27  // empty list anymore, which makes no sense)
28  Object(int __nothing=0) { }
29 
30  Object(feature_t... types) : feature(types...) { }
31 
36  template<typename t>
37  t get() const {
38  return std::get<t>(feature);
39  }
40 
45  template<typename t>
46  void set(t val) {
47  std::get<t>(feature) = val;
48  }
49 
55  template<typename t>
56  bool is(t v) const {
57  return get<t>() == v;
58  }
59 
60  auto operator<=>(const Object& o) const {
61  return feature <=> o.feature;
62  }
63 
64  bool operator==(const Object& o) const {
65  return feature == o.feature;
66  }
67 
71  template<typename... T>
72  static Object<T...> __sample() {
73  Object<T...> ret;
74 
75  // this parameter pack just sets everything assuming __count is
76  // defined in our enum class. C++ is such a weird language.
77  (ret.set( static_cast<T>(myrandom(static_cast<int>(T::__count))) ),
78  ...);
79 
80  return ret;
81  }
82 
83  static Object<feature_t...> sample() {
84  return __sample<feature_t...>();
85  }
86 
87  std::string string() const {
88  std::string out = "[Object";
89  (out += str((int)get<feature_t>()), ...);
90  out += "]";
91  return out;
92  }
93 
94 };
95 
96 template<typename... feature_t>
97 std::ostream& operator<<(std::ostream& o, const Object<feature_t...>& t) {
98  o << t.string();
99  return o;
100 }
T myrandom(T max)
Definition: Random.h:176
std::ostream & operator<<(std::ostream &o, const Object< feature_t... > &t)
Definition: Object.h:97
Object(int __nothing=0)
Definition: Object.h:28
std::string str(BindingTree *t)
Definition: BindingTree.h:195
bool is(t v) const
Check if this feature dimension is a given value.
Definition: Object.h:56
Object(feature_t... types)
Definition: Object.h:30
static Object< feature_t... > sample()
Definition: Object.h:83
static Object< T... > __sample()
Sample a uniformly random object. This requires our features to end in __count.
Definition: Object.h:72
Definition: Object.h:20
This is a thread_local rng whose first object is used to see others (in other threads). This way, we can have thread_local rngs that all are seeded deterministcally in Fleet via –seed=X.
bool operator==(const Object &o) const
Definition: Object.h:64
std::string string() const
Definition: Object.h:87
std::tuple< feature_t... > feature
Definition: Object.h:21