This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
template <typename T> struct MutableState; | |
template <typename T> struct State { | |
State(MutableState<T> &state) : mState{state} {} | |
virtual void observe(std::function<void(T const &)> callback) { | |
mState.mCallback = callback; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <type_traits> | |
#include <tuple> | |
#include <memory> | |
template <typename T, typename ...Args> | |
T inject(Args ...args) { | |
if constexpr (!std::is_pointer_v<T>) { | |
return T{std::forward<Args>(args)...}; | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <type_traits> | |
#include <functional> | |
struct DeferObject { | |
DeferObject() = default; | |
~DeferObject() { | |
mCallback(); | |
} |