AngouriMath
FieldCache.h
1 #pragma once
2 
3 #include "TypeAliases.h"
4 #include <optional>
5 
6 namespace AngouriMath::Internal
7 {
8  template<typename T>
9  class FieldCache
10  {
11  private:
12  std::optional<T> cached;
13  public:
14  // TODO: make thread-safe
15  template<typename Factory>
16  const T& GetValue(Factory&& factory, EntityRef ref)
17  {
18  if (!cached.has_value())
19  cached = factory(ref);
20  return this->cached.value();
21  }
22  };
23 }
Definition: AngouriMath.cpp:20
Definition: FieldCache.h:9