Last active
December 29, 2015 05:39
-
-
Save silvercircle/7623266 to your computer and use it in GitHub Desktop.
member function with named arguments, using boost parameters library
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
/* | |
* 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