#define CreateClass(classname) class classname { \
using Ptr = std::shared_ptr<classname>;
#define CreateStruct(classname) struct classname { \
using Ptr = std::shared_ptr<classname>;
It's pretty ugly, but would do the trick.
Example:
class MyClass {
using Ptr = std::shared_ptr<MyClass>;
virtual ~MyClass() = default;
/* .... */
};
// Equivalent to:
CreateClass(MyClass)
virtual ~MyClass() = default;
/* .... */
};
@EDIT
Expanding the macro a little bit, you can add base classes:
#define _ClassCreation1(classname) class classname { \
using Ptr = std::shared_ptr<classname>;
#define _ClassCreation2(classname, baseclasses) class classname : baseclasses { \
using Ptr = std::shared_ptr<classname>;
#define _ARG2(_0, _1, _2, ...) _2
#define NARG2(...) _ARG2(__VA_ARGS__, 2, 1, 0)
#define _ONE_OR_TWO_ARGS_1(a) _ClassCreation1(a)
#define _ONE_OR_TWO_ARGS_2(a, b) _ClassCreation2(a,b)
#define __ONE_OR_TWO_ARGS(N, ...) _ONE_OR_TWO_ARGS_ ## N (__VA_ARGS__)
#define _ONE_OR_TWO_ARGS(N, ...) __ONE_OR_TWO_ARGS(N, __VA_ARGS__)
#define CreateClass(...) _ONE_OR_TWO_ARGS(NARG2(__VA_ARGS__), __VA_ARGS__)
(based on: https://stackoverflow.com/a/11763196/5589708)
So you would use it like:
CreateClass(MyClass)
virtual ~MyClass() = default;
/* .... */
};
CreateClass(MyClass2, public MyClass)
virtual ~MyClass2() = default;
/* .... */
};