15 #include <type_traits> 18 #define FMT_VERSION 60102 21 # define FMT_HAS_FEATURE(x) __has_feature(x) 23 # define FMT_HAS_FEATURE(x) 0 26 #if defined(__has_include) && !defined(__INTELLISENSE__) && \ 27 !(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600) 28 # define FMT_HAS_INCLUDE(x) __has_include(x) 30 # define FMT_HAS_INCLUDE(x) 0 33 #ifdef __has_cpp_attribute 34 # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) 36 # define FMT_HAS_CPP_ATTRIBUTE(x) 0 39 #if defined(__GNUC__) && !defined(__clang__) 40 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 42 # define FMT_GCC_VERSION 0 45 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) 46 # define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION 48 # define FMT_HAS_GXX_CXX11 0 52 # define FMT_NVCC __NVCC__ 58 # define FMT_MSC_VER _MSC_VER 60 # define FMT_MSC_VER 0 65 #ifndef FMT_USE_CONSTEXPR 66 # define FMT_USE_CONSTEXPR \ 67 (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \ 68 (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) && \ 72 # define FMT_CONSTEXPR constexpr 73 # define FMT_CONSTEXPR_DECL constexpr 75 # define FMT_CONSTEXPR inline 76 # define FMT_CONSTEXPR_DECL 80 # if FMT_HAS_FEATURE(cxx_override) || \ 81 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 82 # define FMT_OVERRIDE override 89 #ifndef FMT_EXCEPTIONS 90 # if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ 91 FMT_MSC_VER && !_HAS_EXCEPTIONS 92 # define FMT_EXCEPTIONS 0 94 # define FMT_EXCEPTIONS 1 99 #ifndef FMT_USE_NOEXCEPT 100 # define FMT_USE_NOEXCEPT 0 103 #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ 104 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 105 # define FMT_DETECTED_NOEXCEPT noexcept 106 # define FMT_HAS_CXX11_NOEXCEPT 1 108 # define FMT_DETECTED_NOEXCEPT throw() 109 # define FMT_HAS_CXX11_NOEXCEPT 0 113 # if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT 114 # define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT 116 # define FMT_NOEXCEPT 121 #if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VER 122 # define FMT_NORETURN [[noreturn]] 124 # define FMT_NORETURN 127 #ifndef FMT_DEPRECATED 128 # if (FMT_HAS_CPP_ATTRIBUTE(deprecated) && __cplusplus >= 201402L) || \ 130 # define FMT_DEPRECATED [[deprecated]] 132 # if defined(__GNUC__) || defined(__clang__) 133 # define FMT_DEPRECATED __attribute__((deprecated)) 135 # define FMT_DEPRECATED __declspec(deprecated) 137 # define FMT_DEPRECATED 143 #if defined(__INTEL_COMPILER) || FMT_NVCC 144 # define FMT_DEPRECATED_ALIAS 146 # define FMT_DEPRECATED_ALIAS FMT_DEPRECATED 149 #ifndef FMT_BEGIN_NAMESPACE 150 # if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \ 152 # define FMT_INLINE_NAMESPACE inline namespace 153 # define FMT_END_NAMESPACE \ 157 # define FMT_INLINE_NAMESPACE namespace 158 # define FMT_END_NAMESPACE \ 160 using namespace v6; \ 163 # define FMT_BEGIN_NAMESPACE \ 165 FMT_INLINE_NAMESPACE v6 { 168 #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) 170 # define FMT_API __declspec(dllexport) 171 # elif defined(FMT_SHARED) 172 # define FMT_API __declspec(dllimport) 173 # define FMT_EXTERN_TEMPLATE_API FMT_API 179 #ifndef FMT_EXTERN_TEMPLATE_API 180 # define FMT_EXTERN_TEMPLATE_API 183 #ifndef FMT_HEADER_ONLY 184 # define FMT_EXTERN extern 190 #if (FMT_HAS_INCLUDE(<string_view>) && \ 191 (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \ 192 (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) 193 # include <string_view> 194 # define FMT_USE_STRING_VIEW 195 #elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L 196 # include <experimental/string_view> 197 # define FMT_USE_EXPERIMENTAL_STRING_VIEW 203 template <
bool B,
class T =
void>
205 template <
bool B,
class T,
class F>
208 template <
typename T>
210 template <
typename T>
212 template <
typename T>
220 #define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0 231 # define FMT_ASSERT(condition, message) 233 # define FMT_ASSERT(condition, message) \ 236 : fmt::internal::assert_fail(__FILE__, __LINE__, (message))) 240 #if defined(FMT_USE_STRING_VIEW) 241 template <
typename Char>
using std_string_view = std::basic_string_view<Char>;
242 #elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW) 243 template <
typename Char>
244 using std_string_view = std::experimental::basic_string_view<Char>;
249 #ifdef FMT_USE_INT128 251 #elif defined(__SIZEOF_INT128__) 252 # define FMT_USE_INT128 1 256 # define FMT_USE_INT128 0 264 template <
typename Int>
271 template <
typename... Ts>
304 : data_(s), size_(std::char_traits<Char>::length(s)) {}
307 template <
typename Traits,
typename Alloc>
309 const std::basic_string<Char, Traits, Alloc>& s)
FMT_NOEXCEPT 337 size_t str_size = size_ < other.
size_ ? size_ : other.
size_;
338 int result = std::char_traits<Char>::compare(data_, other.
data_, str_size);
340 result = size_ == other.
size_ ? 0 : (size_ < other.
size_ ? -1 : 1);
367 #ifndef __cpp_char8_t 373 template <
typename T>
struct is_char : std::false_type {};
374 template <>
struct is_char<char> : std::true_type {};
375 template <>
struct is_char<wchar_t> : std::true_type {};
377 template <>
struct is_char<char16_t> : std::true_type {};
378 template <>
struct is_char<char32_t> : std::true_type {};
396 template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
401 template <
typename Char,
typename Traits,
typename Alloc>
403 const std::basic_string<Char, Traits, Alloc>& s) {
407 template <
typename Char>
412 template <
typename Char,
423 template <
typename S>
426 template <typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
438 template <
typename S>
439 struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
476 template <
typename Char,
typename ErrorHandler =
internal::error_handler>
488 : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {}
495 return format_str_.
begin();
513 if (next_arg_id_ >= 0)
return next_arg_id_++;
514 on_error(
"cannot switch from manual to automatic argument indexing");
523 if (next_arg_id_ > 0)
524 on_error(
"cannot switch from automatic to manual argument indexing");
532 ErrorHandler::on_error(message);
541 template <
typename Char,
typename ErrorHandler =
internal::error_handler>
551 template <
typename T,
typename Char =
char,
typename Enable =
void>
557 template <
typename T,
typename Char,
typename Enable =
void>
560 std::is_convertible<T, int>::value> {};
564 template <
typename T,
typename Context>
566 std::is_constructible<typename Context::template formatter_type<T>>;
589 capacity_ = buf_capacity;
593 virtual void grow(std::size_t capacity) = 0;
600 void operator=(
const buffer&) =
delete;
601 virtual ~
buffer() =
default;
631 if (new_capacity > capacity_) grow(new_capacity);
636 ptr_[size_++] = value;
640 template <
typename U>
void append(
const U* begin,
const U* end);
643 const T&
operator[](std::size_t index)
const {
return ptr_[index]; }
647 template <
typename Container>
654 container_.resize(capacity);
655 this->
set(&container_[0], capacity);
664 template <
typename Container>
666 using bi_iterator = std::back_insert_iterator<Container>;
667 struct accessor : bi_iterator {
668 accessor(bi_iterator iter) : bi_iterator(iter) {}
669 using bi_iterator::container;
671 return *accessor(it).container;
674 template <
typename T,
typename Char =
char,
typename Enable =
void>
680 template <
typename T,
typename Context>
682 std::is_constructible<fallback_formatter<T, typename Context::char_type>>;
712 template <
typename T,
typename Char>
715 #define FMT_TYPE_CONSTANT(Type, constant) \ 716 template <typename Char> \ 717 struct type_constant<Type, Char> : std::integral_constant<type, constant> {} 757 template <
typename Context>
class value {
781 value(
long long val) : long_long_value(val) {}
782 value(
unsigned long long val) : ulong_long_value(val) {}
785 value(
float val) : float_value(val) {}
786 value(
double val) : double_value(val) {}
787 value(
long double val) : long_double_value(val) {}
788 value(
bool val) : bool_value(val) {}
792 string.data = val.
data();
793 string.size = val.
size();
795 value(
const void* val) : pointer(val) {}
797 template <
typename T>
value(
const T& val) {
802 custom.format = format_custom_arg<
804 typename Context::template formatter_type<T>,
812 template <
typename T,
typename Formatter>
818 ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
822 template <
typename Context,
typename T>
849 template <typename T, FMT_ENABLE_IF(is_char<T>::value)>
852 std::is_same<T, char>::value || std::is_same<T, char_type>::value,
853 "mixing character types is disallowed");
863 template <typename T, FMT_ENABLE_IF(is_string<T>::value)>
866 "mixing character types is disallowed");
869 template <
typename T,
886 static_assert(std::is_same<char_type, char>::value,
"invalid string type");
887 return reinterpret_cast<const char*
>(val);
890 static_assert(std::is_same<char_type, char>::value,
"invalid string type");
891 return reinterpret_cast<const char*
>(val);
902 static_assert(!
sizeof(T),
"formatting of non-void pointers is disallowed");
906 template <
typename T,
926 template <
typename T>
929 auto arg = make_arg<Context>(val.
value);
936 template <
typename T,
typename Context>
956 template <
typename ContextType,
typename T>
960 template <
typename Visitor,
typename Ctx>
976 Context& ctx)
const {
977 custom_.format(custom_.value, parse_ctx, ctx);
1003 template <
typename Visitor,
typename Context>
1006 -> decltype(vis(0)) {
1008 switch (
arg.type_) {
1015 return vis(
arg.value_.int_value);
1017 return vis(
arg.value_.uint_value);
1019 return vis(
arg.value_.long_long_value);
1021 return vis(
arg.value_.ulong_long_value);
1024 return vis(
arg.value_.int128_value);
1026 return vis(
arg.value_.uint128_value);
1033 return vis(
arg.value_.bool_value);
1035 return vis(
arg.value_.char_value);
1037 return vis(
arg.value_.float_value);
1039 return vis(
arg.value_.double_value);
1041 return vis(
arg.value_.long_double_value);
1043 return vis(
arg.value_.string.data);
1046 arg.value_.string.size));
1048 return vis(
arg.value_.pointer);
1057 template <
typename Context>
class arg_map {
1071 map_[size_] = {named.
name, named.template deserialize<Context>()};
1077 void operator=(
const arg_map&) =
delete;
1084 for (entry *it = map_, *end = map_ + size_; it != end; ++it) {
1085 if (it->name == name)
return it->arg;
1098 template <
typename Locale>
explicit locale_ref(
const Locale& loc);
1102 template <
typename Locale> Locale
get()
const;
1105 template <
typename> constexpr
unsigned long long encode_types() {
return 0; }
1107 template <
typename Context,
typename Arg,
typename... Args>
1113 template <
typename Context,
typename T>
1121 template <
bool IS_PACKED,
typename Context,
typename T,
1127 template <
bool IS_PACKED,
typename Context,
typename T,
1130 return make_arg<Context>(value);
1160 : out_(out), args_(ctx_args), loc_(loc) {}
1169 void on_error(
const char* message) { error_handler().on_error(message); }
1180 template <
typename Char>
1196 static const size_t num_args =
sizeof...(Args);
1208 static constexpr
unsigned long long types =
1213 : data_{internal::make_arg<is_packed, Context>(args)...} {}
1226 const Args&... args) {
1266 auto num_args = max_size();
1267 if (index < num_args) arg = args_[
index];
1274 val = values_[
index];
1286 template <
typename... Args>
1288 : types_(store.types) {
1289 set_data(store.
data_);
1306 arg = arg.
value_.named_arg->template deserialize<Context>();
1312 return static_cast<int>(is_packed() ? max_packed
1320 template <
typename... Args>
1325 template <
typename... Args>
1332 template <
typename Char>
1335 template <
typename Char>
1338 namespace internal {
1340 template <
typename OutputIt>
1342 template <
typename Container>
1370 #if defined(FMT_ENFORCE_COMPILE_STRING) 1372 "FMT_ENFORCE_COMPILE_STRING requires all format strings to " 1373 "utilize FMT_STRING() or fmt().");
1381 template <
bool... Args>
1385 template <
typename... Args,
typename S,
typename Char =
char_t<S>>
1390 !std::is_reference<Args>())...>::value,
1391 "passing views as lvalues is disallowed");
1392 check_format_string<remove_const_t<remove_reference_t<Args>>...>(format_str);
1396 template <
typename Char>
1400 template <
typename Char>
1421 template <
typename S,
typename T,
typename Char =
char_t<S>>
1428 template <
typename S,
typename T,
typename Char>
1434 template <
typename OutputIt,
typename S,
typename Char =
char_t<S>,
1436 internal::is_contiguous_back_insert_iterator<OutputIt>::value)>
1445 template <
typename Container,
typename S,
typename... Args,
1449 std::back_insert_iterator<Container> out,
const S& format_str,
1456 template <
typename S,
typename Char =
char_t<S>>
1474 template <
typename S,
typename... Args,
typename Char =
char_t<S>>
1475 inline std::basic_string<Char>
format(
const S& format_str, Args&&... args) {
1495 template <
typename S,
typename... Args,
1497 inline void print(std::FILE* f,
const S& format_str, Args&&... args) {
1499 internal::make_args_checked<Args...>(format_str, args...));
1511 template <
typename S,
typename... Args,
1513 inline void print(
const S& format_str, Args&&... args) {
1515 internal::make_args_checked<Args...>(format_str, args...));
1519 #endif // FMT_CORE_H_
named_arg(basic_string_view< Char > name, const T &val)
#define FMT_BEGIN_NAMESPACE
basic_string_view< Char > to_string_view(const Char *s)
FMT_CONSTEXPR unsigned map(unsigned char val)
#define FMT_ASSERT(condition, message)
typename Context::char_type char_type
FMT_CONSTEXPR bool is_arithmetic_type(type t)
format_arg arg(int id) const
internal::error_handler error_handler()
FMT_CONSTEXPR basic_format_parse_context(basic_string_view< Char > format_str, ErrorHandler eh=ErrorHandler())
std::size_t size() const FMT_NOEXCEPT
FMT_API void assert_fail(const char *file, int line, const char *message)
conditional_t< long_short, unsigned, unsigned long long > ulong_type
value(const char_type *val)
decltype(to_string_view(std::declval< S >())) result
void on_error(const char *message)
std::basic_string< Char > vformat(const S &format_str, basic_format_args< buffer_context< Char >> args)
typename internal::void_t_impl< Ts... >::type void_t
FMT_CONSTEXPR iterator end() const
const named_arg_base< char_type > * named_arg
FMT_CONSTEXPR void remove_prefix(size_t n)
constexpr unsigned long long encode_types()
FMT_CONSTEXPR int map(int val)
internal::locale_ref loc_
FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT
FMT_CONSTEXPR bool is_integral_type(type t)
internal::arg_map< basic_format_context > map_
buffer_context< char > format_context
FMT_API void vprint(std::FILE *f, string_view format_str, format_args args)
friend bool operator==(basic_string_view lhs, basic_string_view rhs)
std::is_constructible< typename Context::template formatter_type< T > > has_formatter
FMT_CONSTEXPR const Char & operator[](size_t pos) const
void advance_to(iterator it)
FMT_CONSTEXPR unsigned long long map(unsigned long long val)
friend bool operator<(basic_string_view lhs, basic_string_view rhs)
FMT_CONSTEXPR long_type map(long val)
value(unsigned long long val)
FMT_CONSTEXPR void on_error(const char *message)
FMT_CONSTEXPR char_type map(T val)
named_arg_base(basic_string_view< Char > nm)
std::is_constructible< fallback_formatter< T, typename Context::char_type > > has_fallback_formatter
basic_format_args< basic_format_context > args_
OutputIt vformat_to(OutputIt out, const S &format_str, basic_format_args< buffer_context< Char >> args)
FMT_CONSTEXPR void check_arg_id(int)
FMT_CONSTEXPR uint128_t map(uint128_t val)
const Char & const_reference
FMT_CONSTEXPR int map(short val)
static void format_custom_arg(const void *arg, basic_format_parse_context< char_type > &parse_ctx, Context &ctx)
FMT_CONSTEXPR basic_format_arg< Context > make_arg(const T &value)
void push_back(value< Context > val)
void check_format_string(S)
FMT_CONSTEXPR const named_arg_base< char_type > & map(const named_arg< T, char_type > &val)
conditional_t< long_short, int, long long > long_type
FMT_CONSTEXPR basic_string_view(const std::basic_string< Char, Traits, Alloc > &s) FMT_NOEXCEPT
FMT_CONSTEXPR const void * map(const void *val)
FMT_CONSTEXPR unsigned map(unsigned val)
void print(std::FILE *f, const S &format_str, Args &&... args)
FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT
void vformat_to(basic_memory_buffer< Char > &buf, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< Char >> args)
FMT_CONSTEXPR int next_arg_id()
typename internal::char_t_impl< S >::type char_t
FMT_CONSTEXPR basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT
value(const named_arg_base< char_type > &val)
#define FMT_END_NAMESPACE
basic_string_view< Char > name
FMT_CONSTEXPR long double map(long double val)
FMT_CONSTEXPR size_t size() const
FMT_CONSTEXPR value(unsigned val)
FMT_CONSTEXPR const T & map(const T &val)
checked_ptr< typename Container::value_type > reserve(std::back_insert_iterator< Container > &it, std::size_t n)
string_value< char_type > string
FMT_CONSTEXPR const void * map(std::nullptr_t val)
FMT_CONSTEXPR const char_type * map(const char_type *val)
long double long_double_value
constexpr unsigned long long encode_types()
FMT_CONSTEXPR ulong_type map(unsigned long val)
FMT_CONSTEXPR const char * map(const signed char *val)
std::back_insert_iterator< Container > format_to(std::back_insert_iterator< Container > out, const S &format_str, Args &&... args)
basic_format_context(OutputIt out, basic_format_args< basic_format_context > ctx_args, internal::locale_ref loc=internal::locale_ref())
typename std::enable_if< B, T >::type enable_if_t
basic_format_arg< Context > find(basic_string_view< char_type > name) const
format_arg_store< Context, Args... > make_format_args(const Args &... args)
FMT_CONSTEXPR long long map(long long val)
typename basic_format_context ::char_type char_type
#define FMT_ENABLE_IF(...)
basic_format_arg< Context > deserialize() const
custom_value< Context > custom
typename std::conditional< B, T, F >::type conditional_t
void reserve(std::size_t new_capacity)
std::basic_string< Char > format(const S &format_str, Args &&... args)
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
basic_format_arg< Context > make_arg(const T &value)
T & operator[](std::size_t index)
typename std::remove_reference< T >::type remove_reference_t
container_buffer(Container &c)
FMT_CONSTEXPR value(int val=0)
FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
const T & operator[](std::size_t index) const
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT
std::integral_constant< bool, B > bool_constant
basic_string_view< char_type > name
format_arg_store< buffer_context< Char >, remove_reference_t< Args >... > make_args_checked(const S &format_str, const remove_reference_t< Args > &... args)
FMT_CONSTEXPR int map(signed char val)
FMT_CONSTEXPR const Char * data() const
FMT_CONSTEXPR ErrorHandler error_handler() const
friend bool operator!=(basic_string_view lhs, basic_string_view rhs)
value(basic_string_view< char_type > val)
int compare(basic_string_view other) const
std::is_same< bool_pack< Args..., true >, bool_pack< true, Args... > > all_true
FMT_CONSTEXPR float map(float val)
void push_back(const T &value)
std::size_t capacity() const FMT_NOEXCEPT
basic_string_view< Char > format_str_
FMT_CONSTEXPR const char_type * map(char_type *val)
void resize(std::size_t new_size)
buffer(T *p=nullptr, std::size_t sz=0, std::size_t cap=0) FMT_NOEXCEPT
long long long_long_value
FMT_CONSTEXPR void advance_to(iterator it)
FMT_CONSTEXPR void check_arg_id(basic_string_view< Char >)
FMT_CONSTEXPR iterator begin() const
char data[sizeof(basic_format_arg< buffer_context< Char >>)]
FMT_CONSTEXPR int map(const T *)
FMT_CONSTEXPR bool map(bool val)
FMT_CONSTEXPR unsigned map(unsigned short val)
typename std::remove_const< T >::type remove_const_t
typename result::char_type type
internal::locale_ref locale()
typename basic_format_context ::char_type char_type
unsigned long long ulong_long_value
friend bool operator>(basic_string_view lhs, basic_string_view rhs)
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT
friend bool operator>=(basic_string_view lhs, basic_string_view rhs)
friend bool operator<=(basic_string_view lhs, basic_string_view rhs)
basic_format_arg< Context > arg
FMT_CONSTEXPR basic_string_view< char_type > map(const T &val)
FMT_CONSTEXPR int128_t map(int128_t val)
Container & get_container(std::back_insert_iterator< Container > it)
basic_string_view(const Char *s)
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< buffer_context< Char >> args)
internal::named_arg< T, Char > arg(const S &name, const T &arg)
buffer(std::size_t sz) FMT_NOEXCEPT
FMT_CONSTEXPR const void * map(void *val)
FMT_CONSTEXPR double map(double val)
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
typename basic_string_view< Char >::iterator iterator
void grow(std::size_t capacity) FMT_OVERRIDE
FMT_CONSTEXPR const char * map(const unsigned char *val)
FMT_CONSTEXPR auto map(const T &val) -> decltype(map(static_cast< typename std::underlying_type< T >::type >(val)))
const T * data() const FMT_NOEXCEPT
#define FMT_TYPE_CONSTANT(Type, constant)