From 2963af3d831bb887449b16b942e70adfe438d7fe Mon Sep 17 00:00:00 2001 From: Viatorus Date: Sun, 21 Apr 2024 14:07:01 +0200 Subject: [PATCH] exclude other types from freestanding --- include/emio/buffer.hpp | 2 ++ include/emio/formatter.hpp | 2 ++ include/emio/result.hpp | 24 ++++++++++++++++++++++-- include/emio/std.hpp | 6 +++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/emio/buffer.hpp b/include/emio/buffer.hpp index 2cf708a..2782d32 100644 --- a/include/emio/buffer.hpp +++ b/include/emio/buffer.hpp @@ -311,10 +311,12 @@ struct get_value_type> { using type = typename Container::value_type; }; +#if __STDC_HOSTED__ template struct get_value_type> { using type = Char; }; +#endif template using get_value_type_t = typename get_value_type::type; diff --git a/include/emio/formatter.hpp b/include/emio/formatter.hpp index 905c797..df0a26c 100644 --- a/include/emio/formatter.hpp +++ b/include/emio/formatter.hpp @@ -299,9 +299,11 @@ constexpr const void* ptr(const std::unique_ptr& p) { return p.get(); } +#if __STDC_HOSTED__ template const void* ptr(const std::shared_ptr& p) { return p.get(); } +#endif } // namespace emio diff --git a/include/emio/result.hpp b/include/emio/result.hpp index 7c819db..3116491 100644 --- a/include/emio/result.hpp +++ b/include/emio/result.hpp @@ -9,7 +9,9 @@ #include #include #include -#include +#if __STDC_HOSTED__ +# include +#endif #include #include "detail/predef.hpp" @@ -82,14 +84,32 @@ inline constexpr struct { * - "no value" -> a value should be accessed but result held an error * - "no error" -> a error should be accessed but result held an value */ +#if __STDC_HOSTED__ class bad_result_access : public std::logic_error { public: /** * Constructs the bad result access from a message. * @param msg The exception message. */ - explicit bad_result_access(const std::string_view& msg) : logic_error{msg.data()} {} + explicit bad_result_access(const std::string_view& msg) : logic_error{std::string{msg}} {} }; +#else +class bad_result_access : public std::exception { + public: + /** + * Constructs the bad result access from a message. + * @param msg The exception message. + */ + explicit bad_result_access(const std::string_view& msg) : msg_{msg} {} + + [[nodiscard]] const char* what() const noexcept override { + return msg_.data(); + } + + private: + std::string_view msg_; +}; +#endif namespace detail { diff --git a/include/emio/std.hpp b/include/emio/std.hpp index d8a199a..19f3936 100644 --- a/include/emio/std.hpp +++ b/include/emio/std.hpp @@ -7,7 +7,9 @@ #pragma once #include -#include +#if __STDC_HOSTED__ +# include +#endif #include #include @@ -58,6 +60,7 @@ class formatter : public formatter { } }; +#if __STDC_HOSTED__ /** * Formatter for std::filesystem::path. */ @@ -68,6 +71,7 @@ class formatter : public formatter { return formatter::format(out, arg.native()); } }; +#endif /** * Formatter for std::monostate.