add compile-time formatting switch and empty test

This commit is contained in:
Alexey Ochapov 2020-11-08 04:39:41 +03:00
parent 8a2de0f85d
commit 071142033c
No known key found for this signature in database
GPG Key ID: 9DC52E8F031B8DA8
3 changed files with 38 additions and 0 deletions

View File

@ -252,6 +252,17 @@
# pragma execution_character_set("utf-8") # pragma execution_character_set("utf-8")
#endif #endif
#if defined(FMT_ENABLE_COMPILE_TIME_FORMATTING)
# if !defined(FMT_HEADER_ONLY) || __cplusplus < 202002L
# error "compile time formatting could not be enabled"
# endif
# define FMT_CTF_CONSTEXPR constexpr
# define FMT_USE_CUSTOM_BACK_INSERT_ITERATOR 1
#else
# define FMT_CTF_CONSTEXPR
# define FMT_USE_CUSTOM_BACK_INSERT_ITERATOR 0
#endif
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
// Implementations of enable_if_t and other metafunctions for older systems. // Implementations of enable_if_t and other metafunctions for older systems.

View File

@ -146,6 +146,12 @@ else ()
target_compile_definitions(header-only-test PRIVATE FMT_HEADER_ONLY=1) target_compile_definitions(header-only-test PRIVATE FMT_HEADER_ONLY=1)
endif () endif ()
add_fmt_executable(compile-time-formatting-test
compile-time-formatting-test.cc test-main.cc)
target_link_libraries(compile-time-formatting-test gmock)
target_include_directories(compile-time-formatting-test SYSTEM PUBLIC gtest gmock)
target_link_libraries(compile-time-formatting-test fmt::fmt-header-only)
message(STATUS "FMT_PEDANTIC: ${FMT_PEDANTIC}") message(STATUS "FMT_PEDANTIC: ${FMT_PEDANTIC}")
if (FMT_PEDANTIC) if (FMT_PEDANTIC)

View File

@ -0,0 +1,21 @@
#include <array>
#include <string>
#define FMT_ENABLE_COMPILE_TIME_FORMATTING 1
#include "fmt/format.h"
#include "gmock.h"
#include "gtest-extra.h"
template <size_t max_string_length> struct constexpr_buffer_helper {
template <typename Func>
constexpr constexpr_buffer_helper& modify(Func func) {
func(buffer);
return *this;
}
template <typename T> constexpr bool operator==(const T& rhs) const noexcept {
return (std::string_view(rhs).compare(buffer.data()) == 0);
}
std::array<char, max_string_length> buffer{};
};