Skip to content

Instantly share code, notes, and snippets.

@uliwitness
Last active May 30, 2016 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uliwitness/c7696c5074de10958f14f0a99c2020fb to your computer and use it in GitHub Desktop.
Save uliwitness/c7696c5074de10958f14f0a99c2020fb to your computer and use it in GitHub Desktop.
struct eat_char_fcn
{
eat_char_fcn( struct eat_char_fcn (*inFun)( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ) ) : function(inFun) {}
struct eat_char_fcn operator()( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ) { return function(currCh,reader,nod,att); }
explicit operator bool() { return function != nullptr; }
struct eat_char_fcn (*function)( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att );
};
@uliwitness
Copy link
Author

uliwitness commented May 29, 2016

Could even make this a macro like:

#define RECURSIVE_FUNC_PTR(name,params) struct name \
{ \
    name( struct name (*inFun)params ) : function(inFun) {} \
     \
    struct name operator()params { return function(currCh,reader,nod,att); } \
    explicit operator bool() { return function != nullptr; } \
     \
    struct name (*function)params; \
}

RECURSIVE_FUNC_PTR(eat_char_fcn,( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ));

@uliwitness
Copy link
Author

Note: Got a suggestion to make the operator bool explicit, which should prevent nasty accidental bool conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment