Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created May 17, 2018 03:01
Show Gist options
  • Select an option

  • Save TheBuzzSaw/8e6659736894ea117e6564d835ca796e to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/8e6659736894ea117e6564d835ca796e to your computer and use it in GitHub Desktop.
Action callback
#ifndef ACTION_HPP
#define ACTION_HPP
template<class T> struct Action
{
void (*callback)(T*);
T* data;
};
template<class T> void SafeCall(Action<T> action)
{
if (action.callback) action.callback(action.data);
}
template<class TData, class TValue> struct ValueAction
{
void (*callback)(TData*, TValue);
TData* data;
};
template<class TData, class TValue> void SafeCall(
ValueAction<TData, TValue> action, TValue value)
{
if (action.callback) action.callback(action.data, value);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment