nx_metadata_sdk 1.0 Metadata SDK

Macros | Functions
flags.h File Reference
`#include <type_traits>`

Go to the source code of this file.

## Macros
#define | NX_KIT_API
#define | NX_KIT_ENABLE_FLAGS(ENUM)

## Functions
template<typename Enum >
constexpr std::underlying_type< Enum >::type | nx::kit::flags_detail::toUnderlyingType (Enum value)

## Detailed Description

Facilities to enable bit flags functionality for enums.

Usage example:

        #include <nx/kit/flags.h>
        #include <nx/kit/debug.h>

        enum class Color: unsigned char
        {
            black = 0,

            red = 1 << 0,
            green = 1 << 1,
            blue = 1 << 2,

            yellow = red | green,
            magenta = red | blue,
            cyan = green | blue,

            white = red | green | blue,
        };
        NX_KIT_ENABLE_FLAGS(Color);

        // Class member enumerations are supported.
        struct Border
        {
            // Unscoped enumerations are supported.
            enum CrossDirection
            {
                NoDirection = 0,
                InDirection = 1 << 0,
                OutDirection = 1 << 1,
                EitherDirection = InDirection | OutDirection,
            };
        };
        NX_KIT_ENABLE_FLAGS(Border::CrossDirection);

        int main()
        {
            NX_KIT_ASSERT((Color::magenta | Color::green & ~Color::red) == Color::cyan);
            NX_KIT_ASSERT((Border::OutDirection | Border::InDirection) == Border::EitherDirection);
        }

This header can be included in any C++ project.

## Macro Definition Documentation

## ◆ NX_KIT_ENABLE_FLAGS

#define NX_KIT_ENABLE_FLAGS | ( |  | ENUM | ) |

Enable flag operations for a given enum. Must be invoked at namespace scope in the innermost namespace containing enum declaration.