From db0b726c051f2d631b85793038677caf467a7cfe Mon Sep 17 00:00:00 2001 From: LEE KYOUNGHEON Date: Tue, 28 May 2024 06:17:33 +0900 Subject: [PATCH] Add MAGIC_ENUM_USE_STD_MODULE option to use standard library module. (#350) --- include/magic_enum/magic_enum.hpp | 4 ++++ include/magic_enum/magic_enum_containers.hpp | 4 ++++ include/magic_enum/magic_enum_format.hpp | 2 ++ include/magic_enum/magic_enum_iostream.hpp | 2 ++ .../magic_enum => module}/magic_enum.cppm | 20 +++++++++++++++++++ 5 files changed, 32 insertions(+) rename {include/magic_enum => module}/magic_enum.cppm (80%) diff --git a/include/magic_enum/magic_enum.hpp b/include/magic_enum/magic_enum.hpp index 7adf87715..56b723ac0 100644 --- a/include/magic_enum/magic_enum.hpp +++ b/include/magic_enum/magic_enum.hpp @@ -36,6 +36,7 @@ #define MAGIC_ENUM_VERSION_MINOR 9 #define MAGIC_ENUM_VERSION_PATCH 5 +#ifndef MAGIC_ENUM_USE_STD_MODULE #include #include #include @@ -43,11 +44,13 @@ #include #include #include +#endif #if defined(MAGIC_ENUM_CONFIG_FILE) # include MAGIC_ENUM_CONFIG_FILE #endif +#ifndef MAGIC_ENUM_USE_STD_MODULE #if !defined(MAGIC_ENUM_USING_ALIAS_OPTIONAL) # include #endif @@ -57,6 +60,7 @@ #if !defined(MAGIC_ENUM_USING_ALIAS_STRING_VIEW) # include #endif +#endif #if defined(MAGIC_ENUM_NO_ASSERT) # define MAGIC_ENUM_ASSERT(...) static_cast(0) diff --git a/include/magic_enum/magic_enum_containers.hpp b/include/magic_enum/magic_enum_containers.hpp index 6ccd82a6a..f0022bce2 100644 --- a/include/magic_enum/magic_enum_containers.hpp +++ b/include/magic_enum/magic_enum_containers.hpp @@ -36,10 +36,14 @@ #include "magic_enum.hpp" #if !defined(MAGIC_ENUM_NO_EXCEPTION) && (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) +#ifndef MAGIC_ENUM_USE_STD_MODULE # include +#endif # define MAGIC_ENUM_THROW(...) throw (__VA_ARGS__) #else +#ifndef MAGIC_ENUM_USE_STD_MODULE # include +#endif # define MAGIC_ENUM_THROW(...) std::abort() #endif diff --git a/include/magic_enum/magic_enum_format.hpp b/include/magic_enum/magic_enum_format.hpp index 934462e3e..e1d6f4573 100644 --- a/include/magic_enum/magic_enum_format.hpp +++ b/include/magic_enum/magic_enum_format.hpp @@ -50,7 +50,9 @@ namespace magic_enum::customize { #if defined(__cpp_lib_format) +#ifndef MAGIC_ENUM_USE_STD_MODULE #include +#endif template struct std::formatter> && magic_enum::customize::enum_format_enabled(), char>> : std::formatter { diff --git a/include/magic_enum/magic_enum_iostream.hpp b/include/magic_enum/magic_enum_iostream.hpp index 424e30831..eb618d757 100644 --- a/include/magic_enum/magic_enum_iostream.hpp +++ b/include/magic_enum/magic_enum_iostream.hpp @@ -35,7 +35,9 @@ #include "magic_enum.hpp" #include "magic_enum_flags.hpp" +#ifndef MAGIC_ENUM_USE_STD_MODULE #include +#endif namespace magic_enum { diff --git a/include/magic_enum/magic_enum.cppm b/module/magic_enum.cppm similarity index 80% rename from include/magic_enum/magic_enum.cppm rename to module/magic_enum.cppm index 74f94d7fb..db43bcbaf 100644 --- a/include/magic_enum/magic_enum.cppm +++ b/module/magic_enum.cppm @@ -1,9 +1,23 @@ module; +#include +#ifndef MAGIC_ENUM_USE_STD_MODULE #include +#endif export module magic_enum; +#ifdef MAGIC_ENUM_USE_STD_MODULE +import std; + +extern "C++" { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" +#include +#pragma clang diagnostic pop +} +#endif + export namespace magic_enum { namespace customize { using customize::enum_range; @@ -54,3 +68,9 @@ namespace containers { using magic_enum::underlying_type; using magic_enum::underlying_type_t; } + +#if defined(__cpp_lib_format) +export namespace std { + using std::formatter; +} +#endif