Google OR-Tools: ortools/sat/model.h Source File
48 static inline size_t FastTypeId() {
49 static_assert(sizeof(char*) <= sizeof(size_t),
50 "ptr size too large for size_t");
55 return reinterpret_cast<size_t>(&dummy_var);
73 explicit Model(std::string name) : name_(name) {}
130 const size_t type_id = FastTypeId<T>();
131 auto find = singletons_.find(type_id);
132 if (find != singletons_.end()) {
133 return static_cast<T*>(find->second);
151 const auto& it = singletons_.find(FastTypeId<T>());
152 return it != singletons_.end() ? static_cast<const T*>(it->second)
161 const auto& it = singletons_.find(FastTypeId<T>());
162 return it != singletons_.end() ? static_cast<T*>(it->second) : nullptr;
195 const size_t type_id = FastTypeId<T>();
196 CHECK(!singletons_.contains(type_id));
200 const std::string& Name() const { return name_; }
209 decltype(T(static_cast<Model*>(nullptr)))* MyNew(int) {
220 absl::flat_hash_map< size_t, void*> singletons_;
223 virtual ~DeleteInterface() = default;
226 class Delete : public DeleteInterface {
228 explicit Delete(T* t) : to_delete_(t) {}
229 ~Delete() override = default;
232 std::unique_ptr<T> to_delete_;
240 std::vector<std::unique_ptr<DeleteInterface>> cleanup_list_;