mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 03:07:36 +02:00
Cleanup compile implementation
This commit is contained in:
@ -8,14 +8,8 @@
|
|||||||
#ifndef FMT_COMPILE_H_
|
#ifndef FMT_COMPILE_H_
|
||||||
#define FMT_COMPILE_H_
|
#define FMT_COMPILE_H_
|
||||||
|
|
||||||
#ifndef FMT_HAS_CONSTRUCTIBLE_TRAITS
|
|
||||||
# define FMT_HAS_CONSTRUCTIBLE_TRAITS \
|
|
||||||
(FMT_GCC_VERSION >= 407 || FMT_CLANG_VERSION || FMT_MSC_VER)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "format.h"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "format.h"
|
||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -506,12 +500,10 @@ struct compiletime_parts_provider {
|
|||||||
|
|
||||||
template <typename PartsContainer>
|
template <typename PartsContainer>
|
||||||
struct parts_container_concept_check : std::true_type {
|
struct parts_container_concept_check : std::true_type {
|
||||||
#if FMT_HAS_CONSTRUCTIBLE_TRAITS
|
|
||||||
static_assert(std::is_copy_constructible<PartsContainer>::value,
|
static_assert(std::is_copy_constructible<PartsContainer>::value,
|
||||||
"PartsContainer is not copy constructible");
|
"PartsContainer is not copy constructible");
|
||||||
static_assert(std::is_move_constructible<PartsContainer>::value,
|
static_assert(std::is_move_constructible<PartsContainer>::value,
|
||||||
"PartsContainer is not move constructible");
|
"PartsContainer is not move constructible");
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T, typename = void>
|
template <typename T, typename = void>
|
||||||
struct has_format_part_type : std::false_type {};
|
struct has_format_part_type : std::false_type {};
|
||||||
@ -669,98 +661,77 @@ template <typename Format> struct format_tag {
|
|||||||
|
|
||||||
#if FMT_USE_CONSTEXPR
|
#if FMT_USE_CONSTEXPR
|
||||||
template <typename Format, typename... Args>
|
template <typename Format, typename... Args>
|
||||||
auto do_prepare(runtime_format_tag, Format format) {
|
auto do_compile(runtime_format_tag, Format format) {
|
||||||
return preparator<Format, Args...>::prepare(std::move(format));
|
return preparator<Format, Args...>::prepare(std::move(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Format, typename... Args>
|
template <typename Format, typename... Args>
|
||||||
FMT_CONSTEXPR auto do_prepare(compiletime_format_tag, const Format& format) {
|
FMT_CONSTEXPR auto do_compile(compiletime_format_tag, const Format& format) {
|
||||||
return typename basic_prepared_format<Format, void, Args...>::type(format);
|
return typename basic_prepared_format<Format, void, Args...>::type(format);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <typename Format, typename... Args>
|
template <typename Format, typename... Args>
|
||||||
auto do_prepare(const Format& format)
|
auto do_compile(const Format& format)
|
||||||
-> decltype(preparator<Format, Args...>::prepare(format)) {
|
-> decltype(preparator<Format, Args...>::prepare(format)) {
|
||||||
return preparator<Format, Args...>::prepare(format);
|
return preparator<Format, Args...>::prepare(format);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
template <typename Char, typename Container = std::vector<format_part<Char>>>
|
|
||||||
struct parts_container {
|
|
||||||
typedef internal::parts_container<Char, Container> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Format, typename PartsContainer, typename... Args>
|
|
||||||
struct basic_prepared_format {
|
|
||||||
typedef typename internal::basic_prepared_format<Format, PartsContainer,
|
|
||||||
Args...>::type type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... Args> struct prepared_format {
|
template <typename... Args> struct prepared_format {
|
||||||
typedef typename basic_prepared_format<
|
typedef typename internal::basic_prepared_format<
|
||||||
std::string, typename parts_container<char>::type, Args...>::type type;
|
std::string, internal::parts_container<char>, Args...>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename... Args> struct wprepared_format {
|
template <typename... Args> struct wprepared_format {
|
||||||
typedef
|
typedef typename internal::basic_prepared_format<
|
||||||
typename basic_prepared_format<std::wstring,
|
std::wstring, internal::parts_container<wchar_t>, Args...>::type type;
|
||||||
typename parts_container<wchar_t>::type,
|
|
||||||
Args...>::type type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char, typename Container = std::vector<format_part<Char>>>
|
template <typename... Args>
|
||||||
using parts_container_t = typename parts_container<Char, Container>::type;
|
using prepared_format_t = typename internal::basic_prepared_format<
|
||||||
|
std::string, internal::parts_container<char>, Args...>::type;
|
||||||
template <typename Format, typename PreparedPartsContainer, typename... Args>
|
|
||||||
using basic_prepared_format_t =
|
|
||||||
typename basic_prepared_format<Format, PreparedPartsContainer,
|
|
||||||
Args...>::type;
|
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
using prepared_format_t =
|
using wprepared_format_t = typename internal::basic_prepared_format<
|
||||||
basic_prepared_format_t<std::string, parts_container<char>, Args...>;
|
std::wstring, internal::parts_container<wchar_t>, Args...>::type;
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
using wprepared_format_t =
|
|
||||||
basic_prepared_format_t<std::wstring, parts_container<wchar_t>, Args...>;
|
|
||||||
|
|
||||||
#if FMT_USE_CONSTEXPR
|
#if FMT_USE_CONSTEXPR
|
||||||
|
|
||||||
template <typename... Args, typename Format>
|
template <typename... Args, typename S>
|
||||||
FMT_CONSTEXPR auto compile(Format format) {
|
FMT_CONSTEXPR auto compile(S format_str) {
|
||||||
return internal::do_prepare<Format, Args...>(
|
return internal::do_compile<S, Args...>(
|
||||||
typename internal::format_tag<Format>::type{}, std::move(format));
|
typename internal::format_tag<S>::type{}, std::move(format_str));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
template <typename... Args, typename Format>
|
template <typename... Args, typename S>
|
||||||
auto compile(Format format) ->
|
auto compile(S format_str) ->
|
||||||
typename internal::preparator<Format, Args...>::prepared_format_type {
|
typename internal::preparator<S, Args...>::prepared_format_type {
|
||||||
return internal::preparator<Format, Args...>::prepare(std::move(format));
|
return internal::preparator<S, Args...>::prepare(std::move(format_str));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename... Args, typename Char>
|
template <typename... Args, typename Char>
|
||||||
auto compile(const Char* format) ->
|
auto compile(const Char* format_str) ->
|
||||||
typename internal::preparator<std::basic_string<Char>,
|
typename internal::preparator<std::basic_string<Char>,
|
||||||
Args...>::prepared_format_type {
|
Args...>::prepared_format_type {
|
||||||
return compile<Args...>(internal::to_runtime_format(format));
|
return compile<Args...>(internal::to_runtime_format(format_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args, typename Char, unsigned N>
|
template <typename... Args, typename Char, unsigned N>
|
||||||
auto compile(const Char(format)[N]) ->
|
auto compile(const Char(format_str)[N]) ->
|
||||||
typename internal::preparator<std::basic_string<Char>,
|
typename internal::preparator<std::basic_string<Char>,
|
||||||
Args...>::prepared_format_type {
|
Args...>::prepared_format_type {
|
||||||
const auto view = basic_string_view<Char>(format, N);
|
const auto view = basic_string_view<Char>(format_str, N);
|
||||||
return compile<Args...>(internal::to_runtime_format(view));
|
return compile<Args...>(internal::to_runtime_format(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args, typename Char>
|
template <typename... Args, typename Char>
|
||||||
auto compile(basic_string_view<Char> format) ->
|
auto compile(basic_string_view<Char> format_str) ->
|
||||||
typename internal::preparator<std::basic_string<Char>,
|
typename internal::preparator<std::basic_string<Char>,
|
||||||
Args...>::prepared_format_type {
|
Args...>::prepared_format_type {
|
||||||
return compile<Args...>(internal::to_runtime_format(format));
|
return compile<Args...>(internal::to_runtime_format(format_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
@ -486,9 +486,9 @@ TEST(PrepareTest, ReusedPreparedFormatType) {
|
|||||||
|
|
||||||
TEST(PrepareTest, UserProvidedPartsContainerUnderlyingContainer) {
|
TEST(PrepareTest, UserProvidedPartsContainerUnderlyingContainer) {
|
||||||
typedef fmt::format_part<char> format_part;
|
typedef fmt::format_part<char> format_part;
|
||||||
typedef fmt::parts_container<char, std::list<format_part>>::type
|
typedef fmt::internal::parts_container<char, std::list<format_part>>
|
||||||
parts_container;
|
parts_container;
|
||||||
typedef fmt::basic_prepared_format<std::string, parts_container, std::string,
|
typedef fmt::internal::basic_prepared_format<std::string, parts_container, std::string,
|
||||||
int>::type prepared_format;
|
int>::type prepared_format;
|
||||||
|
|
||||||
prepared_format prepared = fmt::compile<prepared_format>("The {} is {}.");
|
prepared_format prepared = fmt::compile<prepared_format>("The {} is {}.");
|
||||||
@ -532,7 +532,7 @@ class custom_parts_container {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST(PrepareTest, UserProvidedPartsContainer) {
|
TEST(PrepareTest, UserProvidedPartsContainer) {
|
||||||
typedef fmt::basic_prepared_format<std::string, custom_parts_container,
|
typedef fmt::internal::basic_prepared_format<std::string, custom_parts_container,
|
||||||
std::string, int>::type prepared_format;
|
std::string, int>::type prepared_format;
|
||||||
|
|
||||||
prepared_format prepared = fmt::compile<prepared_format>("The {} is {}.");
|
prepared_format prepared = fmt::compile<prepared_format>("The {} is {}.");
|
||||||
|
Reference in New Issue
Block a user