Skip to content

Instantly share code, notes, and snippets.

@njlr
Created September 19, 2017 11:40
Show Gist options
  • Select an option

  • Save njlr/f7265c59d417ec91cf9de70bd43a4d8e to your computer and use it in GitHub Desktop.

Select an option

Save njlr/f7265c59d417ec91cf9de70bd43a4d8e to your computer and use it in GitHub Desktop.
template<class ReturnType, class...Xs>
class SmallFun<ReturnType(Xs...)> {
  char memory[SIZE];
public:
 template<class F>
  SmallFun(F const& f) 
  : new (memory) Model<F, ReturnType, Xs...> {
  assert( sizeof(Model<F, ReturnType, Xs...>) < SIZE ); 
  }
 
 ~SmallFun() {
  if (allocated) {
  ((concept*)memory)->~concept();
  }
  } 
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment