piranha  0.10
Macros
forwarding.hpp File Reference

Forwarding macros. More...

#include <type_traits>
#include <utility>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PIRANHA_FORWARDING_CTOR(Derived, Base)
 Constructor-forwarding macro. More...
 
#define PIRANHA_FORWARDING_ASSIGNMENT(Derived, Base)
 Assignment-forwarding macro. More...
 

Detailed Description

Forwarding macros.

This header contains macros to forward constructors and assignment operators to a base class.

Definition in file forwarding.hpp.

Macro Definition Documentation

◆ PIRANHA_FORWARDING_ASSIGNMENT

#define PIRANHA_FORWARDING_ASSIGNMENT (   Derived,
  Base 
)
Value:
template <typename T_> \
typename std::enable_if<std::is_assignable<Base &, T_ &&>::value \
&& !std::is_base_of<Derived, typename std::decay<T_>::type>::value, \
Derived &>::type \
operator=(T_ &&arg) \
{ \
Base::operator=(std::forward<T_>(arg)); \
return *this; \
}

Assignment-forwarding macro.

This macro will declare and define a generic assignment operator for class Derived. The operator will perfectly forward the argument to the base class Base, and it is enabled only if the base class is assignable from the generic argument. In order to avoid clashes with copy/move assignment operators, in case the argument derives from Derived the operator will be disabled.

Definition at line 68 of file forwarding.hpp.

◆ PIRANHA_FORWARDING_CTOR

#define PIRANHA_FORWARDING_CTOR (   Derived,
  Base 
)
Value:
template < \
typename T_, typename... Args_, \
typename = typename std:: \
enable_if<std::is_constructible<Base, T_ &&, Args_ &&...>::value \
&& (sizeof...(Args_) || !std::is_base_of<Derived, typename std::decay<T_>::type>::value)>::type> \
explicit Derived(T_ &&arg0, Args_ &&... args) : Base(std::forward<T_>(arg0), std::forward<Args_>(args)...) \
{ \
}
STL namespace.

Constructor-forwarding macro.

This macro will declare and define an explicit constructor for class Derived that accepts a variadic set of arguments whose size is greater than zero. The constructor will perfectly forward the arguments to the base class Base, and it is enabled only if the base class is constructible from the set of arguments. In order to avoid clashes with copy/move constructors, in case the only argument derives from Derived the constructor will be disabled.

Definition at line 50 of file forwarding.hpp.