|
Loading...
Searching...
No Matches
Go to the documentation of this file.
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
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
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
121#if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VER
122# define FMT_NORETURN [[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
203template < bool B, class T = void>
205template < bool B, class T, class F>
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)
241template < typename Char> using std_string_view = std::basic_string_view<Char>;
242#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
243template < typename Char>
244using std_string_view = std::experimental::basic_string_view<Char>;
251#elif defined(__SIZEOF_INT128__)
252# define FMT_USE_INT128 1
256# define FMT_USE_INT128 0
264template < typename Int>
267 return static_cast<typename std::make_unsigned<Int>::type >( value);
271template < 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
338 int result = std::char_traits<Char>::compare( data_, other. data_, str_size);
373template < typename T> struct is_char : std::false_type {};
374template <> struct is_char<char> : std::true_type {};
375template <> struct is_char<wchar_t> : std::true_type {};
377template <> struct is_char<char16_t> : std::true_type {};
378template <> struct is_char<char32_t> : std::true_type {};
396template < typename Char, FMT_ENABLE_IF(is_ char<Char>::value)>
401template < typename Char, typename Traits, typename Alloc>
403 const std::basic_string<Char, Traits, Alloc>& s) {
407template < typename Char>
412template < typename Char,
426template < typename S, FMT_ENABLE_IF(is_compile_ string<S>::value)>
433using fmt::v6::to_string_view;
439struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
445 using type = typename result::char_type;
476template < typename Char, typename ErrorHandler = internal::error_handler>
514 on_error( "cannot switch from manual to automatic argument indexing");
524 on_error( "cannot switch from automatic to manual argument indexing");
532 ErrorHandler::on_error(message);
541template < typename Char, typename ErrorHandler = internal::error_handler>
551template < typename T, typename Char = char, typename Enable = void>
557template < typename T, typename Char, typename Enable = void>
560 std::is_convertible<T, int>::value> {};
564template < typename T, typename Context>
566 std::is_constructible<typename Context::template formatter_type<T>>;
647template < typename Container>
664template < 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;
674template < typename T, typename Char = char, typename Enable = void>
680template < typename T, typename Context>
682 std::is_constructible<fallback_formatter<T, typename Context::char_type>>;
685template < typename T, typename Char> struct named_arg;
712template < 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> {}
757template < typename Context> class value {
792 string.data = val. data();
793 string.size = val. size();
797 template < typename T> value( const T& val) {
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));
822template < 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)>
865 static_assert(std::is_same<char_type, char_t<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,
911 map( static_cast<typename std::underlying_type<T>::type >(val))) {
912 return map( static_cast<typename std::underlying_type<T>::type >(val));
926 template < typename T>
929 auto arg = make_arg<Context>(val. value);
936template < typename T, typename Context>
939 typename Context::char_type>;
946template < typename Context> class arg_map;
956 template < typename ContextType, typename T>
960 template < typename Visitor, typename Ctx>
976 Context& ctx) const {
1003template < typename Visitor, typename Context>
1006 -> decltype(vis(0)) {
1007 using char_type = typename Context::char_type;
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);
1071 map_[ size_] = {named. name, named.template deserialize<Context>()};
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;
1105template < typename> constexpr unsigned long long encode_types() { return 0; }
1107template < typename Context, typename Arg, typename... Args>
1113template < typename Context, typename T>
1121template < bool IS_PACKED, typename Context, typename T,
1127template < bool IS_PACKED, typename Context, typename T,
1130 return make_arg<Context>( value);
1180template < typename Char>
1208 static constexpr unsigned long long types =
1226 const Args&... args) {
1267 if (index < num_args) arg = args_[index];
1286 template < typename... Args>
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>
1332template < typename Char>
1335template < typename Char>
1340template < typename OutputIt>
1342template < 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().");
1381template < bool... Args>
1385template < typename... Args, typename S, typename Char = char_t<S>>
1389 static_assert( all_true<(!std::is_base_of<view, remove_reference_t<Args>>() ||
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);
1396template < typename Char>
1400template < typename Char>
1421template < typename S, typename T, typename Char = char_t<S>>
1428template < typename S, typename T, typename Char>
1434template < typename OutputIt, typename S, typename Char = char_t<S>,
1436 internal::is_contiguous_back_insert_iterator<OutputIt>::value)>
1445template < typename Container, typename S, typename... Args,
1449 std::back_insert_iterator<Container> out, const S& format_str,
1456template < typename S, typename Char = char_t<S>>
1474template < typename S, typename... Args, typename Char = char_t<S>>
1475inline std::basic_string<Char> format( const S& format_str, Args&&... args) {
1495template < typename S, typename... Args,
1497inline void print(std::FILE* f, const S& format_str, Args&&... args) {
1499 internal::make_args_checked<Args...>(format_str, args...));
1511template < typename S, typename... Args,
1513inline void print( const S& format_str, Args&&... args) {
1515 internal::make_args_checked<Args...>(format_str, args...));
format_arg arg(int id) const
void advance_to(iterator it)
basic_format_context(OutputIt out, basic_format_args< basic_format_context > ctx_args, internal::locale_ref loc=internal::locale_ref())
internal::locale_ref locale()
void on_error(const char *message)
internal::arg_map< basic_format_context > map_
void operator=(const basic_format_context &)=delete
basic_format_args< basic_format_context > args_
basic_format_arg< basic_format_context > format_arg
internal::error_handler error_handler()
basic_format_context(const basic_format_context &)=delete
internal::locale_ref loc_
FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT
FMT_CONSTEXPR void advance_to(iterator it)
FMT_CONSTEXPR void on_error(const char *message)
FMT_CONSTEXPR void check_arg_id(int)
FMT_CONSTEXPR void check_arg_id(basic_string_view< Char >)
FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT
typename basic_string_view< Char >::iterator iterator
basic_string_view< Char > format_str_
FMT_CONSTEXPR ErrorHandler error_handler() const
FMT_CONSTEXPR int next_arg_id()
FMT_CONSTEXPR basic_format_parse_context(basic_string_view< Char > format_str, ErrorHandler eh=ErrorHandler())
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)
FMT_CONSTEXPR void remove_prefix(size_t n)
int compare(basic_string_view other) const
FMT_CONSTEXPR size_t size() const
friend bool operator!=(basic_string_view lhs, basic_string_view rhs)
FMT_CONSTEXPR iterator end() const
friend bool operator>(basic_string_view lhs, basic_string_view rhs)
FMT_CONSTEXPR const Char * data() const
friend bool operator<=(basic_string_view lhs, basic_string_view rhs)
FMT_CONSTEXPR basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT
FMT_CONSTEXPR iterator begin() const
FMT_CONSTEXPR basic_string_view(const std::basic_string< Char, Traits, Alloc > &s) FMT_NOEXCEPT
friend bool operator==(basic_string_view lhs, basic_string_view rhs)
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT
basic_string_view(const Char *s)
FMT_CONSTEXPR const Char & operator[](size_t pos) const
void init(const basic_format_args< Context > &args)
basic_format_arg< Context > find(basic_string_view< char_type > name) const
arg_map(const arg_map &)=delete
void operator=(const arg_map &)=delete
typename Context::char_type char_type
void push_back(value< Context > val)
void reserve(std::size_t new_capacity)
const T & operator[](std::size_t index) const
buffer(T *p=nullptr, std::size_t sz=0, std::size_t cap=0) FMT_NOEXCEPT
void append(const U *begin, const U *end)
buffer(const buffer &)=delete
buffer(std::size_t sz) FMT_NOEXCEPT
void operator=(const buffer &)=delete
void push_back(const T &value)
virtual void grow(std::size_t capacity)=0
void resize(std::size_t new_size)
virtual ~buffer()=default
std::size_t size() const FMT_NOEXCEPT
const T * data() const FMT_NOEXCEPT
void set(T *buf_data, std::size_t buf_capacity) FMT_NOEXCEPT
const T & const_reference
T & operator[](std::size_t index)
std::size_t capacity() const FMT_NOEXCEPT
container_buffer(Container &c)
void grow(std::size_t capacity) FMT_OVERRIDE
static void format_custom_arg(const void *arg, basic_format_parse_context< char_type > &parse_ctx, Context &ctx)
const named_arg_base< char_type > * named_arg
custom_value< Context > custom
FMT_CONSTEXPR value(int val=0)
value(const char_type *val)
value(unsigned long long val)
long long long_long_value
value(basic_string_view< char_type > val)
FMT_CONSTEXPR value(unsigned val)
typename Context::char_type char_type
string_value< char_type > string
long double long_double_value
value(const named_arg_base< char_type > &val)
unsigned long long ulong_long_value
typename std::enable_if< B, T >::type enable_if_t
#define FMT_ASSERT(condition, message)
std::integral_constant< bool, B > bool_constant
#define FMT_TYPE_CONSTANT(Type, constant)
std::back_insert_iterator< Container > format_to(std::back_insert_iterator< Container > out, const S &format_str, Args &&... args)
internal::named_arg< T, Char > arg(const S &name, const T &arg)
typename std::remove_const< T >::type remove_const_t
typename std::remove_reference< T >::type remove_reference_t
buffer_context< char > format_context
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
OutputIt vformat_to(OutputIt out, const S &format_str, basic_format_args< buffer_context< Char > > args)
FMT_API void vprint(std::FILE *f, string_view format_str, format_args args)
format_arg_store< Context, Args... > make_format_args(const Args &... args)
#define FMT_BEGIN_NAMESPACE
FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
std::is_constructible< typename Context::template formatter_type< T > > has_formatter
basic_string_view< Char > to_string_view(const Char *s)
#define FMT_ENABLE_IF(...)
typename internal::char_t_impl< S >::type char_t
void print(std::FILE *f, const S &format_str, Args &&... args)
typename std::conditional< B, T, F >::type conditional_t
std::basic_string< Char > vformat(const S &format_str, basic_format_args< buffer_context< Char > > args)
std::basic_string< Char > format(const S &format_str, Args &&... args)
#define FMT_END_NAMESPACE
typename internal::void_t_impl< Ts... >::type void_t
constexpr unsigned long long encode_types()
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)
Container & get_container(std::back_insert_iterator< Container > it)
conditional_t< long_short, unsigned, unsigned long long > ulong_type
FMT_CONSTEXPR bool is_arithmetic_type(type t)
FMT_API void assert_fail(const char *file, int line, const char *message)
FMT_CONSTEXPR basic_format_arg< Context > make_arg(const T &value)
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
format_arg_store< buffer_context< Char >, remove_reference_t< Args >... > make_args_checked(const S &format_str, const remove_reference_t< Args > &... args)
std::is_constructible< fallback_formatter< T, typename Context::char_type > > has_fallback_formatter
std::is_same< bool_pack< Args..., true >, bool_pack< true, Args... > > all_true
void check_format_string(const S &)
conditional_t< long_short, int, long long > long_type
FMT_CONSTEXPR bool is_integral_type(type t)
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< buffer_context< Char > > args)
basic_format_arg< Context > arg
basic_string_view< char_type > name
FMT_CONSTEXPR basic_string_view< char_type > map(const T &val)
FMT_CONSTEXPR int map(int val)
FMT_CONSTEXPR unsigned map(unsigned val)
FMT_CONSTEXPR const char_type * map(char_type *val)
FMT_CONSTEXPR const char * map(const unsigned char *val)
FMT_CONSTEXPR ulong_type map(unsigned long val)
FMT_CONSTEXPR long_type map(long val)
FMT_CONSTEXPR const char * map(const signed char *val)
FMT_CONSTEXPR const void * map(const void *val)
FMT_CONSTEXPR unsigned long long map(unsigned long long val)
FMT_CONSTEXPR int128_t map(int128_t val)
FMT_CONSTEXPR const named_arg_base< char_type > & map(const named_arg< T, char_type > &val)
FMT_CONSTEXPR int map(signed char val)
FMT_CONSTEXPR float map(float val)
FMT_CONSTEXPR uint128_t map(uint128_t val)
FMT_CONSTEXPR char_type map(T val)
FMT_CONSTEXPR bool map(bool val)
FMT_CONSTEXPR double map(double val)
FMT_CONSTEXPR const void * map(std::nullptr_t val)
FMT_CONSTEXPR int map(const T *)
FMT_CONSTEXPR const T & map(const T &val)
FMT_CONSTEXPR auto map(const T &val) -> decltype(map(static_cast< typename std::underlying_type< T >::type >(val)))
typename Context::char_type char_type
FMT_CONSTEXPR const void * map(void *val)
FMT_CONSTEXPR const char_type * map(const char_type *val)
FMT_CONSTEXPR long double map(long double val)
FMT_CONSTEXPR unsigned map(unsigned char val)
FMT_CONSTEXPR unsigned map(unsigned short val)
FMT_CONSTEXPR int map(short val)
FMT_CONSTEXPR long long map(long long val)
typename result::char_type type
decltype(to_string_view(std::declval< S >())) result
void(* format)(const void *arg, parse_context &parse_ctx, Context &ctx)
FMT_CONSTEXPR error_handler(const error_handler &)=default
FMT_CONSTEXPR error_handler()=default
FMT_NORETURN FMT_API void on_error(const char *message)
named_arg_base(basic_string_view< Char > nm)
basic_format_arg< Context > deserialize() const
basic_string_view< Char > name
char data[sizeof(basic_format_arg< buffer_context< Char > >)]
named_arg(basic_string_view< Char > name, const T &val)
|