Skip to content

Commit

Permalink
exclude other types from freestanding
Browse files Browse the repository at this point in the history
  • Loading branch information
Viatorus committed Apr 21, 2024
1 parent 64c89b9 commit 2963af3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/emio/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ struct get_value_type<std::back_insert_iterator<Container>> {
using type = typename Container::value_type;
};

#if __STDC_HOSTED__
template <typename Char, typename Traits>
struct get_value_type<std::ostreambuf_iterator<Char, Traits>> {
using type = Char;
};
#endif

template <typename T>
using get_value_type_t = typename get_value_type<T>::type;
Expand Down
2 changes: 2 additions & 0 deletions include/emio/formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,11 @@ constexpr const void* ptr(const std::unique_ptr<T, Deleter>& p) {
return p.get();
}

#if __STDC_HOSTED__
template <typename T>
const void* ptr(const std::shared_ptr<T>& p) {
return p.get();
}
#endif

} // namespace emio
24 changes: 22 additions & 2 deletions include/emio/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <concepts>
#include <cstdint>
#include <optional>
#include <stdexcept>
#if __STDC_HOSTED__
# include <stdexcept>
#endif
#include <type_traits>

#include "detail/predef.hpp"
Expand Down Expand Up @@ -82,14 +84,32 @@ inline constexpr struct {
* - "no value" -> a value should be accessed but result<T> held an error
* - "no error" -> a error should be accessed but result<T> 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 {

Expand Down
6 changes: 5 additions & 1 deletion include/emio/std.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#pragma once

#include <exception>
#include <filesystem>
#if __STDC_HOSTED__
# include <filesystem>
#endif
#include <optional>
#include <variant>

Expand Down Expand Up @@ -58,6 +60,7 @@ class formatter<T> : public formatter<std::string_view> {
}
};

#if __STDC_HOSTED__
/**
* Formatter for std::filesystem::path.
*/
Expand All @@ -68,6 +71,7 @@ class formatter<std::filesystem::path> : public formatter<std::string_view> {
return formatter<std::string_view>::format(out, arg.native());
}
};
#endif

/**
* Formatter for std::monostate.
Expand Down

0 comments on commit 2963af3

Please sign in to comment.