Embedded Template Library 1.0
Loading...
Searching...
No Matches

Topics

 alignment
 cyclic_value
 reference_wrapper
 type_traits

Namespaces

namespace  etl

Classes

class  etl::nullopt_t
class  etl::optional< T >

Macros

#define ETL_DECLARE_DEBUG_COUNT
#define ETL_HAS_CONSTEXPR_ENDIANNESS   0
#define ETL_DECLARE_ENUM_TYPE(TypeName, ValueType)
#define ETL_DECLARE_USER_TYPE(TypeName, ValueType)
#define ETL_VERSION_MAJOR   20

Variables

const nullopt_t etl::nullopt = {}

Detailed Description

A set of utility templates.


Class Documentation

◆ etl::nullopt_t

class etl::nullopt_t

A null option type.

Public Member Functions

template<class T>
 operator T* () const

◆ etl::optional

class etl::optional
template<typename T>
class etl::optional< T >

An optional type. If the optional type is not initialised then a type is not constructed. See http://en.cppreference.com/w/cpp/utility/optional

Template Parameters
TThe type to store.

Public Types

typedef T value_type
typedef T * iterator
typedef const T * const_iterator

Public Member Functions

 optional (etl::nullopt_t) ETL_NOEXCEPT
 Constructor with nullopt.
 optional (const optional &other)
 Copy constructor.
 optional (const T &value_)
 Construct from value type.
optional & operator= (etl::nullopt_t) ETL_NOEXCEPT
 Assignment operator from nullopt.
optional & operator= (const optional &other)
 Assignment operator from optional.
optional & operator= (const T &value_)
 Assignment operator from value type.
ETL_CONSTEXPR20_STL iterator begin () ETL_NOEXCEPT
 Returns an iterator to the beginning of the optional.
ETL_CONSTEXPR20_STL const_iterator begin () const ETL_NOEXCEPT
 Returns a const iterator to the beginning of the optional.
ETL_CONSTEXPR20_STL iterator end () ETL_NOEXCEPT
 Returns an iterator to the end of the optional.
ETL_CONSTEXPR20_STL const_iterator end () const ETL_NOEXCEPT
 Returns a const iterator to the end of the optional.

Macro Definition Documentation

◆ ETL_DECLARE_DEBUG_COUNT

#define ETL_DECLARE_DEBUG_COUNT
Value:
enum \
{ \
etl_debug_count_suppressed__ = 0 \
}

◆ ETL_DECLARE_ENUM_TYPE

#define ETL_DECLARE_ENUM_TYPE ( TypeName,
ValueType )
Value:
typedef ValueType value_type; \
ETL_CONSTEXPR TypeName() \
: value(static_cast<enum_type>(value_type())) \
{ \
} \
ETL_CONSTEXPR TypeName(enum_type value_) \
: value(value_) \
{ \
} \
ETL_CONSTEXPR explicit TypeName(value_type value_) \
: value(static_cast<enum_type>(value_)) \
{ \
} \
ETL_CONSTEXPR operator value_type() const \
{ \
return static_cast<value_type>(value); \
} \
ETL_CONSTEXPR value_type get_value() const \
{ \
return static_cast<value_type>(value); \
} \
ETL_CONSTEXPR enum_type get_enum() const \
{ \
return value; \
} \
ETL_CONSTEXPR14 const char* c_str() const \
{ \
switch (value) \
{
struct CompassDirection
{
enum enum_type
{
North = 0,
South = 180,
East = 90,
West = 270
};
ETL_DECLARE_ENUM_TYPE(CompassDirection, int)
ETL_ENUM_TYPE(North, "North")
ETL_ENUM_TYPE(South, "South")
ETL_ENUM_TYPE(East, "East")
ETL_ENUM_TYPE(West, "West")
ETL_END_ENUM_TYPE
};
#define ETL_DECLARE_ENUM_TYPE(TypeName, ValueType)
Definition enum_type.h:90

Using the enumeration.

CompassDirection direction; // Default construction.
direction = CompassDirection::North; // Assignment from an enumeration
constant;
int value = direction; // Implicit conversion to 'int'.
direction = CompassDirection(value); // Explicit conversion from 'int'.
direction = CompassDirection(3); // Explicit conversion from an invalid
value. This unfortunately cannot be avoided. Caveat emptor!
direction = value; // Implicit conversion from 'int'. ****
Compilation error ****
std::cout << "Direction = " << direction.c_str(); // Prints "Direction =
North"

If a conversion to a string is not required then the 'ETL_ENUM_TYPE' declaration may be omitted. In that case the c_str() function will return a "?". This will also be the case for any enumeration value that does not have an ETL_ENUM_TYPE entry.

◆ ETL_DECLARE_USER_TYPE

#define ETL_DECLARE_USER_TYPE ( TypeName,
ValueType )
ETL_DECLARE_USER_TYPE(CompassDirection, int)
ETL_USER_TYPE(North, 0)
ETL_USER_TYPE(South, 180)
ETL_USER_TYPE(East, 90)
ETL_USER_TYPE(West, 270)
ETL_END_USER_TYPE(CompassDirection)
#define ETL_DECLARE_USER_TYPE(TypeName, ValueType)
Definition user_type.h:80

Using the enumeration.

CompassDirection direction; // Default construction.
direction = CompassDirection::North; // Assignment from an enumeration
constant;
int value = int(direction); // Explicit conversion to 'int'.
int value = direction.get();
int& value = direction.get(); // Bind to internal value.
const int& value = direction.get();
direction = CompassDirection(value); // Explicit conversion from 'int'.
direction = CompassDirection(3); // Explicit conversion from a value.
++direction; // Manipulate the value;
direction -= CompassDirection(20);
direction = value; // Implicit conversion from 'int'. ****
Compilation error ****

Variable Documentation

◆ nullopt

const nullopt_t etl::nullopt = {}

A null option.