Program Listing for File enum-class-operators.h

Return to documentation for file (include\utility\enum-class-operators.h)

/******************************************************************************
© Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.


 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once

#include <type_traits>

#define GPA_DEFINE_ENUM_CLASS_OPERATORS(GPA_ENUM_TYPE)                                                         \
                                                                                                               \
    inline GPA_ENUM_TYPE& operator++(GPA_ENUM_TYPE& value)                                                     \
    {                                                                                                          \
        value = static_cast<GPA_ENUM_TYPE>(static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(value) + 1); \
        return value;                                                                                          \
    }                                                                                                          \
                                                                                                               \
    inline GPA_ENUM_TYPE operator++(GPA_ENUM_TYPE& value, int)                                                 \
    {                                                                                                          \
        auto temp = value;                                                                                     \
        ++value;                                                                                               \
        return temp;                                                                                           \
    }                                                                                                          \
                                                                                                               \
    inline GPA_ENUM_TYPE& operator--(GPA_ENUM_TYPE& value)                                                     \
    {                                                                                                          \
        value = static_cast<GPA_ENUM_TYPE>(static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(value) - 1); \
        return value;                                                                                          \
    }                                                                                                          \
                                                                                                               \
    inline GPA_ENUM_TYPE operator--(GPA_ENUM_TYPE& value, int)                                                 \
    {                                                                                                          \
        auto temp = value;                                                                                     \
        --value;                                                                                               \
        return temp;                                                                                           \
    }                                                                                                          \
                                                                                                               \
    inline GPA_ENUM_TYPE operator+(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)           \
    {                                                                                                          \
        return static_cast<GPA_ENUM_TYPE>(static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) + rhs);  \
    }                                                                                                          \
                                                                                                               \
    inline GPA_ENUM_TYPE operator-(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)           \
    {                                                                                                          \
        return static_cast<GPA_ENUM_TYPE>(static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) - rhs);  \
    }                                                                                                          \
                                                                                                               \
    inline bool operator==(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)                   \
    {                                                                                                          \
        return static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) == rhs;                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator==(std::underlying_type<GPA_ENUM_TYPE>::type lhs, GPA_ENUM_TYPE rhs)                   \
    {                                                                                                          \
        return lhs == static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(rhs);                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator!=(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)                   \
    {                                                                                                          \
        return static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) != rhs;                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator!=(std::underlying_type<GPA_ENUM_TYPE>::type lhs, GPA_ENUM_TYPE rhs)                   \
    {                                                                                                          \
        return lhs != static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(rhs);                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator<(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)                    \
    {                                                                                                          \
        return static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) < rhs;                              \
    }                                                                                                          \
                                                                                                               \
    inline bool operator<(std::underlying_type<GPA_ENUM_TYPE>::type lhs, GPA_ENUM_TYPE rhs)                    \
    {                                                                                                          \
        return lhs < static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(rhs);                              \
    }                                                                                                          \
                                                                                                               \
    inline bool operator<=(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)                   \
    {                                                                                                          \
        return static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) <= rhs;                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator<=(std::underlying_type<GPA_ENUM_TYPE>::type lhs, GPA_ENUM_TYPE rhs)                   \
    {                                                                                                          \
        return lhs <= static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(rhs);                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator>(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)                    \
    {                                                                                                          \
        return static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) > rhs;                              \
    }                                                                                                          \
                                                                                                               \
    inline bool operator>(std::underlying_type<GPA_ENUM_TYPE>::type lhs, GPA_ENUM_TYPE rhs)                    \
    {                                                                                                          \
        return lhs > static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(rhs);                              \
    }                                                                                                          \
                                                                                                               \
    inline bool operator>=(GPA_ENUM_TYPE lhs, std::underlying_type<GPA_ENUM_TYPE>::type rhs)                   \
    {                                                                                                          \
        return static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(lhs) >= rhs;                             \
    }                                                                                                          \
                                                                                                               \
    inline bool operator>=(std::underlying_type<GPA_ENUM_TYPE>::type lhs, GPA_ENUM_TYPE rhs)                   \
    {                                                                                                          \
        return lhs >= static_cast<std::underlying_type<GPA_ENUM_TYPE>::type>(rhs);                             \
    }