Skip to content

Commit

Permalink
fix and improve module:
Browse files Browse the repository at this point in the history
* export public documented API
* don't export `namespace detail`
* add `std.h` into module
* add missing namespace qualification in `xchar.h`
* fix call to `detail::get_iterator` in `xchar.h`
* fix ambiguous overload of `detail::isfinite` in `chrono.h`
  • Loading branch information
DanielaE committed Apr 16, 2023
1 parent 8ec94ac commit 28757cd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class dynamic_arg_list {
}
};
} // namespace detail
FMT_BEGIN_EXPORT

/**
\rst
Expand Down Expand Up @@ -229,6 +230,7 @@ class dynamic_format_arg_store
}
};

FMT_END_EXPORT
FMT_END_NAMESPACE

#endif // FMT_ARGS_H_
2 changes: 1 addition & 1 deletion include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ struct chrono_format_checker : null_chrono_spec_handler<chrono_format_checker> {
FMT_CONSTEXPR void on_duration_unit() {}
};

template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value && has_isfinite<T>::value)>
inline bool isfinite(T) {
return true;
}
Expand Down
14 changes: 14 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
#endif

FMT_BEGIN_NAMESPACE
FMT_BEGIN_EXPORT

// Implementations of enable_if_t and other metafunctions for older systems.
template <bool B, typename T = void>
Expand Down Expand Up @@ -295,6 +296,7 @@ inline auto format_as(std::byte b) -> unsigned char {
}
#endif

FMT_END_EXPORT
namespace detail {
// Suppresses "unused variable" warnings with the method described in
// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
Expand Down Expand Up @@ -386,6 +388,7 @@ FMT_CONSTEXPR inline auto is_utf8() -> bool {
uchar(section[1]) == 0xA7);
}
} // namespace detail
FMT_BEGIN_EXPORT

/**
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
Expand Down Expand Up @@ -502,6 +505,7 @@ using string_view = basic_string_view<char>;
template <typename T> struct is_char : std::false_type {};
template <> struct is_char<char> : std::true_type {};

FMT_END_EXPORT
namespace detail {

// A base class for compile-time strings.
Expand Down Expand Up @@ -635,6 +639,7 @@ struct error_handler {
}
};
} // namespace detail
FMT_BEGIN_EXPORT

/** String's character type. */
template <typename S> using char_t = typename detail::char_t_impl<S>::type;
Expand Down Expand Up @@ -713,6 +718,7 @@ template <typename Char> class basic_format_parse_context {

using format_parse_context = basic_format_parse_context<char>;

FMT_END_EXPORT
namespace detail {
// A parse context with extra data used only in compile-time checks.
template <typename Char>
Expand Down Expand Up @@ -752,6 +758,7 @@ class compile_parse_context : public basic_format_parse_context<Char> {
}
};
} // namespace detail
FMT_BEGIN_EXPORT

template <typename Char>
FMT_CONSTEXPR void basic_format_parse_context<Char>::do_check_arg_id(int id) {
Expand Down Expand Up @@ -799,6 +806,7 @@ struct is_contiguous<std::basic_string<Char>> : std::true_type {};

class appender;

FMT_END_EXPORT
namespace detail {

template <typename Context, typename T>
Expand Down Expand Up @@ -1476,6 +1484,7 @@ enum { max_packed_args = 62 / packed_arg_bits };
enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
} // namespace detail
FMT_BEGIN_EXPORT

// An output iterator that appends to a buffer.
// It is used to reduce symbol sizes for the common case.
Expand Down Expand Up @@ -1594,6 +1603,7 @@ FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(
return vis(monostate());
}

FMT_END_EXPORT
namespace detail {

template <typename Char, typename InputIt>
Expand Down Expand Up @@ -1710,6 +1720,7 @@ FMT_CONSTEXPR inline auto make_arg(T&& value) -> basic_format_arg<Context> {
return make_arg<Context>(value);
}
} // namespace detail
FMT_BEGIN_EXPORT

// Formatting context.
template <typename OutputIt, typename Char> class basic_format_context {
Expand Down Expand Up @@ -1998,6 +2009,7 @@ enum type FMT_ENUM_UNDERLYING_TYPE(unsigned char){none, minus, plus, space};
}
using sign_t = sign::type;

FMT_END_EXPORT
namespace detail {

// Workaround an array initialization issue in gcc 4.8.
Expand All @@ -2024,6 +2036,7 @@ template <typename Char> struct fill_t {
}
};
} // namespace detail
FMT_BEGIN_EXPORT

enum class presentation_type : unsigned char {
none,
Expand Down Expand Up @@ -2068,6 +2081,7 @@ template <typename Char = char> struct format_specs {
localized(false) {}
};

FMT_END_EXPORT
namespace detail {

enum class arg_id_kind { none, index, name };
Expand Down
16 changes: 12 additions & 4 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ inline void write_escaped_path<std::filesystem::path::value_type>(
}

} // namespace detail
FMT_BEGIN_EXPORT

template <typename Char>
struct formatter<std::filesystem::path, Char>
Expand All @@ -91,16 +92,20 @@ struct formatter<std::filesystem::path, Char>
basic_string_view<Char>(quoted.data(), quoted.size()), ctx);
}
};
FMT_END_EXPORT
FMT_END_NAMESPACE
#endif

FMT_BEGIN_NAMESPACE
FMT_BEGIN_EXPORT
template <typename Char>
struct formatter<std::thread::id, Char> : basic_ostream_formatter<Char> {};
FMT_END_EXPORT
FMT_END_NAMESPACE

#ifdef __cpp_lib_optional
FMT_BEGIN_NAMESPACE
FMT_BEGIN_EXPORT
template <typename T, typename Char>
struct formatter<std::optional<T>, Char,
std::enable_if_t<is_formattable<T, Char>::value>> {
Expand Down Expand Up @@ -139,11 +144,13 @@ struct formatter<std::optional<T>, Char,
return detail::write(out, ')');
}
};
FMT_END_EXPORT
FMT_END_NAMESPACE
#endif // __cpp_lib_optional

#ifdef __cpp_lib_variant
FMT_BEGIN_NAMESPACE
FMT_BEGIN_EXPORT
template <typename Char> struct formatter<std::monostate, Char> {
template <typename ParseContext>
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
Expand All @@ -159,7 +166,7 @@ template <typename Char> struct formatter<std::monostate, Char> {
}
};

namespace detail {
FMT_BEGIN_DETAIL_NAMESPACE

template <typename T>
using variant_index_sequence =
Expand Down Expand Up @@ -191,8 +198,7 @@ auto write_variant_alternative(OutputIt out, const T& v) -> OutputIt {
return write<Char>(out, v);
}

} // namespace detail

FMT_END_DETAIL_NAMESPACE
template <typename T> struct is_variant_like {
static constexpr const bool value = detail::is_variant_like_<T>::value;
};
Expand Down Expand Up @@ -231,11 +237,12 @@ struct formatter<
return out;
}
};
FMT_END_EXPORT
FMT_END_NAMESPACE
#endif // __cpp_lib_variant

FMT_BEGIN_NAMESPACE

FMT_BEGIN_EXPORT
template <typename Char> struct formatter<std::error_code, Char> {
template <typename ParseContext>
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
Expand Down Expand Up @@ -338,6 +345,7 @@ struct formatter<
return out;
}
};
FMT_END_EXPORT
FMT_END_NAMESPACE

#endif // FMT_STD_H_
4 changes: 2 additions & 2 deletions include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ inline auto vformat_to(
auto&& buf = detail::get_buffer<Char>(out);
vformat_to(buf, detail::to_string_view(format_str), args,
detail::locale_ref(loc));
return detail::get_iterator(buf);
return detail::get_iterator(buf, out);
}

template <
Expand All @@ -181,7 +181,7 @@ template <
inline auto format_to(OutputIt out, const Locale& loc, const S& format_str,
Args&&... args) ->
typename std::enable_if<enable, OutputIt>::type {
return vformat_to(out, loc, to_string_view(format_str),
return vformat_to(out, loc, detail::to_string_view(format_str),
fmt::make_format_args<buffer_context<Char>>(args...));
}

Expand Down
7 changes: 7 additions & 0 deletions src/fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ module;
#include <cstring>
#include <ctime>
#include <exception>
#include <filesystem>
#include <fstream>
#include <functional>
#include <iterator>
#include <limits>
#include <locale>
#include <memory>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <thread>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
#include <version>

#if _MSC_VER
# include <intrin.h>
Expand Down Expand Up @@ -75,6 +81,7 @@ export module fmt;
#include "fmt/os.h"
#include "fmt/printf.h"
#include "fmt/xchar.h"
#include "fmt/std.h"

// gcc doesn't yet implement private module fragments
#if !FMT_GCC_VERSION
Expand Down

0 comments on commit 28757cd

Please sign in to comment.