Gromacs
2024.3
|
#include <cstddef>
#include <iterator>
#include <type_traits>
#include <gromacs/external/boost/stl_interfaces/iterator_interface.hpp>
#include "gromacs/utility/gmxassert.h"
Defines helper types for class enumerations.
These helper types facilitate iterating over class enums, and maintaining a type-safe and value-safe matching list of names. The code is closely based on the public-domain code by Guilherme R. Lampert, found in commit c94c18a of https://github.com/glampert/enum_helpers/blob/master/enum_helpers.hpp Thanks Guilherme!
NOTE This functionality only works for enumerations of monotonically increasing values, starting with the value zero.
Usage examples:
enum class Foo : int { Bar, Baz, Fooz, Count };
for (Foo c : EnumerationWrapper<Foo>{}) { // 'c' is a constant from Foo }
const EnumerationArray<Foo, std::string> fooStrings = { { "Bar", "Baz", "Fooz" } }; std::cout << fooStrings[Foo::Baz]; std::cout << fooStrings[Foo::Count]; // Triggers an assertion
for (Foo c : keysOf(fooStrings)) { print(fooStrings[c]); }
ArrayRef<const std::string> namesRef(fooStrings);
Classes | |
class | gmx::EnumerationIterator< EnumType, Last, Step > |
Allows iterating sequential enumerators. More... | |
class | gmx::EnumerationWrapper< EnumType, Last, Step > |
Allows constructing iterators for looping over sequential enumerators. More... | |
struct | gmx::EnumerationArray< EnumType, DataType, ArraySize > |
Wrapper for a C-style array with size and indexing defined by an enum. Useful for declaring arrays of enum names for debug or other printing. An ArrayRef<DataType> may be constructed from an object of this type. More... | |
Functions | |
template<typename EnumerationArrayType > | |
EnumerationArrayType::EnumerationWrapperType | gmx::keysOf (const EnumerationArrayType &) |
Returns an object that provides iterators over the keys associated with EnumerationArrayType . More... | |