Move fmt::format to fmt/format.h

This commit is contained in:
Victor Zverovich
2024-01-10 06:43:12 -08:00
parent fc8f6ba934
commit 4331abed26
5 changed files with 127 additions and 146 deletions
+1 -58
View File
@@ -15,39 +15,6 @@
#include <cstddef> // std::byte
#include <type_traits> // std::enable_if
#if defined(_LIBCPP_VERSION)
# define FMT_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
# define FMT_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
# define FMT_STD_TEMPLATE_VIS _LIBCPP_TEMPLATE_VIS
# define FMT_BEGIN_NAMESPACE_CXX11
# define FMT_END_NAMESPACE_CXX11
#elif defined(_GLIBCXX_RELEASE)
# define FMT_BEGIN_NAMESPACE_STD \
namespace std _GLIBCXX_VISIBILITY(default) { \
_GLIBCXX_BEGIN_NAMESPACE_VERSION
# define FMT_END_NAMESPACE_STD \
_GLIBCXX_END_NAMESPACE_VERSION \
}
# define FMT_STD_TEMPLATE_VIS
# if defined(_GLIBCXX_USE_CXX11_ABI)
# define FMT_BEGIN_NAMESPACE_CXX11 inline _GLIBCXX_BEGIN_NAMESPACE_CXX11
# define FMT_END_NAMESPACE_CXX11 _GLIBCXX_END_NAMESPACE_CXX11
# endif
#else
# include <string>
#endif
#ifdef FMT_BEGIN_NAMESPACE_STD
FMT_BEGIN_NAMESPACE_STD
template <typename Char> struct FMT_STD_TEMPLATE_VIS char_traits;
template <typename T> class FMT_STD_TEMPLATE_VIS allocator;
FMT_BEGIN_NAMESPACE_CXX11
template <typename Char, typename Traits, typename Allocator>
class FMT_STD_TEMPLATE_VIS basic_string;
FMT_END_NAMESPACE_CXX11
FMT_END_NAMESPACE_STD
#endif // FMT_BEGIN_NAMESPACE_STD
// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 100202
@@ -474,14 +441,8 @@ inline auto get_container(OutputIt it) -> typename OutputIt::container_type& {
}
} // namespace detail
template <typename Char>
using basic_string =
std::basic_string<Char, std::char_traits<Char>, std::allocator<Char>>;
// Checks whether T is a container with contiguous storage.
template <typename T> struct is_contiguous : std::false_type {};
template <typename Char>
struct is_contiguous<basic_string<Char>> : std::true_type {};
/**
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
@@ -1957,6 +1918,7 @@ constexpr auto make_format_args(T&... args)
return {args...};
}
// DEPRECATED!
template <typename Context, typename... T>
using format_arg_store =
decltype(make_format_args<Context>(std::declval<T&>()...));
@@ -2803,25 +2765,6 @@ using format_string = basic_format_string<char, type_identity_t<Args>...>;
inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
#endif
FMT_API auto vformat(string_view fmt, format_args args) -> basic_string<char>;
/**
\rst
Formats ``args`` according to specifications in ``fmt`` and returns the result
as a string.
**Example**::
#include <fmt/core.h>
std::string message = fmt::format("The answer is {}.", 42);
\endrst
*/
template <typename... T, typename Char = char>
FMT_NODISCARD FMT_INLINE auto format(format_string<T...> fmt, T&&... args)
-> basic_string<Char> {
return vformat(fmt, fmt::make_format_args(args...));
}
/** Formats a string and writes the output to ``out``. */
template <typename OutputIt,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>