Version: SMASH-3.4
cxx17compat.h
Go to the documentation of this file.
1 
2 /*
3  *
4  * Copyright (c) 2023-2024
5  * SMASH Team
6  *
7  * GNU General Public License (GPLv3 or later)
8  *
9  */
10 
11 #ifndef SRC_INCLUDE_SMASH_CXX17COMPAT_H_
12 #define SRC_INCLUDE_SMASH_CXX17COMPAT_H_
13 
14 #include <optional>
15 #include <type_traits>
16 #include <utility>
17 
18 namespace smash {
19 
20 // GCC_COMPILER macro is defined in CMake code when appropriate
21 #if defined(GCC_COMPILER) && (__GNUC__ == 8 && __GNUC_MINOR__ < 4)
22 /**
23  * An utility function to circumvent GNU compiler bug in some versions.
24  *
25  * Explicitly specifying the template parameter when using
26  * \c std::make_optional is not correctly implemented in GNU compiler
27  * from version 8.1.x to version 8.3.x (both included). See
28  * https://stackoverflow.com/q/75653199/14967071 for an example.
29  *
30  * @tparam T The optional type
31  * @param value The value to be used to construct the \c std::optional
32  * @return A \c std::optional<T> holding \c value
33  */
34 template <typename T>
35 std::optional<T> make_optional(T&& value) {
36  return std::optional<std::decay_t<T>>(std::forward<T>(value));
37 }
38 #else
39 using std::make_optional;
40 #endif
41 
42 #if __cplusplus < 202002L
43 /**
44  * Definition for remove_cvref type trait, which is in C++20's standard library
45  *
46  * \see https://en.cppreference.com/w/cpp/types/remove_cvref
47  */
48 template <class T>
49 struct remove_cvref {
50  /// The type with striped properties
51  using type = std::remove_cv_t<std::remove_reference_t<T>>;
52 };
53 /**
54  * Helper alias which is always defined next to a type trait.
55  */
56 template <class T>
58 #else
59 using std::remove_cvref;
61 #endif
62 
63 } // namespace smash
64 
65 #endif // SRC_INCLUDE_SMASH_CXX17COMPAT_H_
Definition: action.h:24
typename remove_cvref< T >::type remove_cvref_t
Helper alias which is always defined next to a type trait.
Definition: cxx17compat.h:57
Definition for remove_cvref type trait, which is in C++20's standard library.
Definition: cxx17compat.h:49
std::remove_cv_t< std::remove_reference_t< T > > type
The type with striped properties.
Definition: cxx17compat.h:51