X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3a1ea70a418f393ca1677074e928c664022295bd..e15846cf268bfbeed4694bea0ac1492eada00175:/include/xbt/utility.hpp diff --git a/include/xbt/utility.hpp b/include/xbt/utility.hpp index be9d287f56..cab7266e0f 100644 --- a/include/xbt/utility.hpp +++ b/include/xbt/utility.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2016-2020. The SimGrid Team. +/* Copyright (c) 2016-2021. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,8 +7,24 @@ #ifndef XBT_UTILITY_HPP #define XBT_UTILITY_HPP -#include +#include #include +#include +#include + +/** @brief Helper macro to declare enum class + * + * Declares an enum class EnumType, and a function "const char* to_c_str(EnumType)" to retrieve a C-string description + * for each value. + */ +#define XBT_DECLARE_ENUM_CLASS(EnumType, ...) \ + enum class EnumType; \ + static constexpr char const* to_c_str(EnumType value) \ + { \ + constexpr std::array names{{_XBT_STRINGIFY_ARGS(__VA_ARGS__)}}; \ + return names[static_cast(value)]; \ + } \ + enum class EnumType { __VA_ARGS__ } /* defined here to handle trailing semicolon */ namespace simgrid { namespace xbt {