Skip to content

Instantly share code, notes, and snippets.

@silvercircle
Last active December 29, 2015 05:39
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 silvercircle/7623266 to your computer and use it in GitHub Desktop.
Save silvercircle/7623266 to your computer and use it in GitHub Desktop.
member function with named arguments, using boost parameters library
/*
* member function with named arguments, using boost parameters library
*/
#include <memory>
#include <boost/parameter/name.hpp>
#include <boost/parameter/preprocessor.hpp>
// just make it look prettier
#define __Param(x) BOOST_PARAMETER_NAME(x)
#define NamedParamMethod BOOST_PARAMETER_MEMBER_FUNCTION
class Worker : public QObject {
Q_OBJECT
public:
Worker(QObject *parent = 0) : QObject(parent) {}
public slots:
void run();
signals:
void finished();
};
// use these names for named arguments
__Param(arg1)
__Param(arg2)
__Param(flag)
class MyClass {
public:
MyClass(const QString& name) {}
~MyClass() {}
NamedParamMethod(
// return type, function name, tag (tag is doing most of the black voodoo magic behind all this)
(int), foo, tag,
// arg list
(required
(arg1, (int))
)
(optional
(arg2, (int), 10)
(flag, (bool), false)
)
)
{
return(foo_impl(arg1, arg2, flag));
}
private:
int foo_impl(int arg1, int arg2, bool flag);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment