X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/785ebfad2fff4fde55104258e52218b153c035a0..17aced0a546331763cb211027c454fc0930d1f45:/include/xbt/utility.hpp?ds=sidebyside diff --git a/include/xbt/utility.hpp b/include/xbt/utility.hpp index 9634819ed9..03458064d3 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-2022. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,8 +7,10 @@ #ifndef XBT_UTILITY_HPP #define XBT_UTILITY_HPP +#include #include #include +#include #include /** @brief Helper macro to declare enum class @@ -21,13 +23,25 @@ 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)); \ } \ enum class EnumType { __VA_ARGS__ } /* defined here to handle trailing semicolon */ namespace simgrid { namespace 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 * * It can hash pairs: the standard hash currently doesn't include this.