X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1873716d14492d8aa1c51586eb7a4c6d80420c62..39e98567c557d81dd5011b8e2ae883d4674b0c9d:/include/xbt/utility.hpp diff --git a/include/xbt/utility.hpp b/include/xbt/utility.hpp index cab7266e0f..c35be72d7f 100644 --- a/include/xbt/utility.hpp +++ b/include/xbt/utility.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2016-2021. The SimGrid Team. +/* Copyright (c) 2016-2023. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,6 +10,7 @@ #include #include #include +#include #include /** @brief Helper macro to declare enum class @@ -22,12 +23,27 @@ static constexpr char const* to_c_str(EnumType value) \ { \ constexpr std::array names{{_XBT_STRINGIFY_ARGS(__VA_ARGS__)}}; \ - return names[static_cast(value)]; \ + return names.at(static_cast(value)); \ + } \ + static constexpr bool is_valid_##EnumType(int raw_value) \ + { \ + return raw_value >= 0 && raw_value < _XBT_COUNT_ARGS(__VA_ARGS__); \ } \ enum class EnumType { __VA_ARGS__ } /* defined here to handle trailing semicolon */ -namespace simgrid { -namespace xbt { +namespace simgrid::xbt { + +/** @brief Replacement for C++20's std::type_identity_t + */ +#if __cplusplus >= 201806L // __cpp_lib_type_identity +template using type_identity_t = typename std::type_identity_t; +#else +template struct type_identity { + using type = T; +}; + +template using type_identity_t = typename type_identity::type; +#endif /** @brief A hash which works with more stuff * @@ -63,6 +79,5 @@ template inline void intrusive_erase(List& list, Elem& list.erase(list.iterator_to(elem)); } -} -} +} // namespace simgrid::xbt #endif