Skip to content

Strongly typed enumeration support #50

Open
@danishcake

Description

@danishcake

C++11 introduces enum classes which are not implicitly convertible to integers. This stops the standard CHECK_EQUAL etc macros from working.

To fix this you then have to write a streaming operator

std::ostream& operator<<(std::ostream& os, const EnumeratedType& val)
{
os << static_cast<std::underlying_type::type>(val);
return os;
}

or cast to an int in the macro.

CHECK_EQUAL((int)EnumeratedType::OK, (int)actual);

This gets old pretty fast. Is there a possibility of writing some clever template trickery to support enum classes? It could be selectively enabled by detection of c++11.

std::enable_if, std::is_enum look like good starting points.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions