distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
EnumClassFlags.hpp File Reference

Header with templated bitwise operators for enum class flags. More...

#include <type_traits>
Include dependency graph for EnumClassFlags.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  estd::isEnumClassFlags< T >
 Tag struct used to enable bitwise operators for selected enum class flags. More...
 

Namespaces

 estd
 Collection of useful templates.
 

Functions

template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T >::type operator & (const T &left, const T &right)
 Bitwise AND operator. More...
 
template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T >::type operator| (const T &left, const T &right)
 Bitwise OR operator. More...
 
template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T >::type operator^ (const T &left, const T &right)
 Bitwise XOR operator. More...
 
template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T >::type operator~ (const T &object)
 Bitwise NOT operator. More...
 
template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T & >::type operator&= (T &left, const T &right)
 Bitwise AND assignment operator. More...
 
template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T & >::type operator|= (T &left, const T &right)
 Bitwise OR assignment operator. More...
 
template<typename T >
constexpr std::enable_if< estd::isEnumClassFlags< T >{}, T & >::type operator^= (T &left, const T &right)
 Bitwise XOR assignment operator. More...
 

Detailed Description

Header with templated bitwise operators for enum class flags.

Implementation based on Using Enum Classes as Bitfields

Author
Copyright (C) 2019 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
License
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Function Documentation

◆ operator &()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T>::type operator & ( const T &  left,
const T &  right 
)

Bitwise AND operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]leftis the object on the left-hand side of operator
[in]rightis the object on the right-hand side of operator
Returns
result of bitwise AND of left and right

◆ operator&=()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T&>::type operator&= ( T &  left,
const T &  right 
)

Bitwise AND assignment operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]leftis the object on the left-hand side of operator
[in]rightis the object on the right-hand side of operator
Returns
reference to left after it was assigned the result of bitwise AND of left and right

◆ operator^()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T>::type operator^ ( const T &  left,
const T &  right 
)

Bitwise XOR operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]leftis the object on the left-hand side of operator
[in]rightis the object on the right-hand side of operator
Returns
result of bitwise XOR of left and right

◆ operator^=()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T&>::type operator^= ( T &  left,
const T &  right 
)

Bitwise XOR assignment operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]leftis the object on the left-hand side of operator
[in]rightis the object on the right-hand side of operator
Returns
reference to left after it was assigned the result of bitwise XOR of left and right

◆ operator|()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T>::type operator| ( const T &  left,
const T &  right 
)

Bitwise OR operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]leftis the object on the left-hand side of operator
[in]rightis the object on the right-hand side of operator
Returns
result of bitwise OR of left and right

◆ operator|=()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T&>::type operator|= ( T &  left,
const T &  right 
)

Bitwise OR assignment operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]leftis the object on the left-hand side of operator
[in]rightis the object on the right-hand side of operator
Returns
reference to left after it was assigned the result of bitwise OR of left and right

◆ operator~()

template<typename T >
constexpr std::enable_if<estd::isEnumClassFlags<T>{}, T>::type operator~ ( const T &  object)

Bitwise NOT operator.

Template Parameters
Tis the type of enum class flags for which there exists a specialization of estd::isEnumClassFlags which inherits from std::true_type
Parameters
[in]objectis the object on which the operator will act
Returns
result of bitwise NOT of object