Skip to content

Commit

Permalink
Improve self resolvable.
Browse files Browse the repository at this point in the history
  • Loading branch information
crupest committed Jan 1, 2024
1 parent c4641ca commit cf43615
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/cru/common/SelfResolvable.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class ObjectResolver {
return *this->shared_object_ptr_;
}

/**
* @remarks So this class can be used as a functor.
*/
T* operator()() const { return Resolve(); }

private:
void SetResolvedObject(T* o) {
assert(IsValid());
Expand All @@ -38,6 +43,15 @@ class ObjectResolver {
std::shared_ptr<T*> shared_object_ptr_;
};

/**
* @remarks
* This class is not copyable and movable since subclass is polymorphic and
* copying is then nonsense. However, you can even delete move capability in
* subclass because it may also be nonsense for subclass. The move capability is
* optional.
*
* Whether this class needs to be thread-safe still has to be considered.
*/
template <typename T>
class SelfResolvable {
public:
Expand Down

0 comments on commit cf43615

Please sign in to comment.