18 #define FOLLY_FORMAT_H_ 23 #include <type_traits> 39 template <
bool containerMode,
class...
Args>
41 template <
class...
Args>
45 template <
class T,
class Enable =
void>
71 template <
class Derived,
bool containerMode,
class...
Args>
77 template <
class Output>
78 void operator()(Output& out)
const;
86 auto appender = [&str](
StringPiece s) { str.append(
s.data(),
s.size()); };
119 return *
static_cast<const Derived*
>(
this);
122 template <
size_t K,
class Callback>
125 arg.
error(
"argument index out of range, max=", i);
128 template <
size_t K,
class Callback>
132 asDerived().template doFormatArg<K>(arg, cb);
134 doFormatFrom<K + 1>(
i, arg, cb);
138 template <
class Callback>
140 return doFormatFrom<0>(
i, arg, cb);
147 arg.
error(
"argument index out of range, max=", i);
151 typename std::enable_if<
155 return static_cast<int>(format.getValue());
159 typename std::enable_if<
163 arg.
error(
"dynamic field width argument must be integral");
167 typename std::enable_if <
171 return getValue(getFormatValue<K>(), arg);
173 return getSizeArgFrom<K + 1>(
i, arg);
176 int getSizeArg(
size_t i,
const FormatArg& arg)
const {
177 return getSizeArgFrom<0>(
i, arg);
203 std::get<K>(values_));
209 template <
bool containerMode,
class...
Args>
211 Formatter<containerMode, Args...>,
217 Formatter<containerMode,
Args...>,
221 !containerMode ||
sizeof...(
Args) == 1,
222 "Exactly one argument required in container mode");
225 template <
size_t K,
class Callback>
227 this->
template getFormatValue<K>().
format(arg, cb);
231 Formatter<containerMode,
Args...>,
235 template <
class...
A>
244 template <
bool containerMode,
class...
Args>
249 out.write(sp.data(), std::streamsize(sp.size()));
258 template <
class Derived,
bool containerMode,
class...
Args>
270 template <
class...
Args>
272 return Formatter<
false,
Args...>(fmt, std::forward<Args>(args)...);
279 template <
class...
Args>
281 return format(fmt, std::forward<Args>(args)...).str();
297 template <
class Container>
306 template <
class Container>
308 return vformat(fmt, std::forward<Container>(container)).str();
327 return what() + kMessagePrefix.size();
331 static constexpr
StringPiece const kMessagePrefix =
"format key not found: ";
342 template <
class Container,
class Value>
345 : container(container), defaultValue(defaultValue) {}
352 template <
class Container,
class Value>
367 template <
class Str,
class...
Args>
370 format(fmt, std::forward<Args>(args)...).appendTo(*out);
376 template <
class Str,
class Container>
379 vformat(fmt, std::forward<Container>(container)).appendTo(*out);
385 namespace format_value {
393 template <
class FormatCallback>
403 template <
class FormatCallback>
416 class FormatCallback,
451 template <
class T,
class Enable =
void>
457 typename
std::enable_if<
458 std::is_same<typename T::IsFormatter, detail::FormatterTag>::value>::
464 template <
class...
Args>
466 return format(fmt, std::forward<Args>(args)...);
468 template <
class...
Args>
470 return formatChecked(fmt, std::forward<Args>(args)...).str();
472 template <
class Container>
475 Container&& container) {
476 return vformat(fmt, std::forward<Container>(container));
478 template <
class Container>
480 return vformatChecked(fmt, std::forward<Container>(container)).str();
482 template <
class Str,
class...
Args>
485 formatChecked(fmt, std::forward<Args>(args)...).appendTo(*out);
487 template <
class Str,
class Container>
490 vformatChecked(fmt, std::forward<Container>(container)).appendTo(*out);
#define FOLLY_GNU_DISABLE_WARNING(warningName)
#define FOLLY_POP_WARNING
#define FOLLY_PUSH_WARNING
std::string svformatChecked(StringPiece fmt, Container &&container)
std::string sformat(StringPiece fmt, Args &&...args)
std::enable_if< IsSomeString< Str >::value >::type vformatChecked(Str *out, StringPiece fmt, Container &&container)
std::enable_if< IsSomeString< Str >::value >::type vformat(Str *out, StringPiece fmt, Container &&container)
std::enable_if< IsSomeString< Str >::value >::type formatChecked(Str *out, StringPiece fmt, Args &&...args)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
void writeTo(FILE *fp, const BaseFormatter< Derived, containerMode, Args... > &formatter)
detail::DefaultValueWrapper< Container, Value > defaulted(const Container &c, const Value &v)
std::ostream & operator<<(std::ostream &out, const Formatter< containerMode, Args... > &formatter)
bool_constant< true > true_type
std::string sformatChecked(StringPiece fmt, Args &&...args)
bool Value(const T &value, M matcher)
Append appendTo(Collection &collection)
static const char *const value
DefaultValueWrapper(const Container &container, const Value &defaultValue)
const Value & defaultValue
std::enable_if< IsSomeString< Str >::value >::type format(Str *out, StringPiece fmt, Args &&...args)
std::string svformat(StringPiece fmt, Container &&container)
bool_constant< false > false_type
GMockOutputTest ExpectedCall FILE
const Container & container