How can I #define
a type that has a double colon in C++?
For example, I want to include the std::optional
type from the std library. The code bellow won't work because the compiler cannot parse the double colon in #define my_namespace::optional
.
#if __cplusplus >= 201703L // C++17
#include <optional>
#define my_namespace::optional std::optional
#else
#include <my_optional.h>
#define my_namespace::optional my_namespace::my_optional
#endif
// Use the optional type
my_namespace::optional<int32_t> some_value;