A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd

parameter_type

Allows the method of passing a parameter to be determined by the type.
By default, if the type is fundamental or a pointer, then the parameter type is 'by value', otherwise 'by const reference'.

template <typename T, const bool should_pass_by_value = is_fundamental<T>::value ||
                                                        is_pointer<T>::value>
struct parameter_type;

// Pass by value.
template <typename T>
struct parameter_type<T, true>
{
  typedef T type;
};

// Pass by const reference.
template <typename T>
struct parameter_type<T, false>
{
  typedef const T& type;
};

Example

template <typename T>
void Do_Stuff(typename etl::parameter_type<T>::type parameter)
{
}

// Pass by value.
int i = 1;
Do_Stuff(i);

// Pass by const reference.
etl::vector<int, 10> data;
Do_Stuff(data);
parameter_type.h