cxxomfort  rel.20210622
Simple backports for C++ - http://ryan.gulix.cl/fossil.cgi/cxxomfort/
Macros
_codegen.hpp File Reference

Code generation macros and utilities. More...

Macros

#define CXXO_DEFAULT_DEFAULT_CONSTRUCTOR(Type)   Type () = default [or equivalent]
 Declares a “ =default ” default constructor. More...
 
#define CXXO_DEFAULT_COPY_CONSTRUCTOR(Type, Su, ...)
 Declares a =default copy constructor. More...
 
#define CXXO_TYPEOF(expr)   __typeof__(expr) [or equivalent]
 Obtains the type of expr if there is a __typeof__-like facility to do so. More...
 

Detailed Description

Code generation macros and utilities.

Macro Definition Documentation

◆ CXXO_DEFAULT_DEFAULT_CONSTRUCTOR

#define CXXO_DEFAULT_DEFAULT_CONSTRUCTOR (   Type)    Type () = default [or equivalent]

Declares a “ =default ” default constructor.

Codegen:

Using this macro in the body of a class will invoke, where available, the =default default constructor. In pre-C++11, it will invoke a throw() empty constructor.

class Foo {
//In >= C++11 equivalent to:
Foo () noexcept = default;
};

◆ CXXO_DEFAULT_COPY_CONSTRUCTOR

#define CXXO_DEFAULT_COPY_CONSTRUCTOR (   Type,
  Su,
  ... 
)
Value:
[if >=C++11] Type (Type const& ) Su = default \
[else] Type (Type const& From) Su : __VA_ARGS__ {}

Declares a =default copy constructor.

Parameters
Suconstructor suffix (eg.: noexcept)
...Explicit constructor body (for C++03)
Codegen:

Using this macro in the body of a class invokes, starting with C++11, a =default copy constructor. In C++03, it generates the code for a copy constructor using the subsequent arguments to the macro as code for the member initializer list, using the variable name From for the argument of the copy constructor.

class Foo {
CXXO_DEFAULT_COPY_CONSTRUCTOR(Foo, , member(From.member) );
//In >= C++11 equivalent to:
Foo (Foo const&) = default;
//In < C++11 equivalent to:
Foo (Foo const& From) : member(From.member) {}
private:
float member;
};

◆ CXXO_TYPEOF

#define CXXO_TYPEOF (   expr)    __typeof__(expr) [or equivalent]

Obtains the type of expr if there is a __typeof__-like facility to do so.

Parameters
exprAn expression evaluating to a type. Since this is a macro, it can't take commas.

In C++11 onwards, this evaluates to decltype(expr) ; in other modes, it will ealuate to __typeof__(expr) if the feature is available or will error out if not.

Referenced by cxxomfort::cxxostd::bind_front(), and cxxomfort::cxxostd::invoke_r().