Format string example
#include <iostream>
class Date
{
public:
Date(int year, int month, int day) : _year(year), _month(month), _day(day) {}
int year() const { return _year; }
int month() const { return _month; }
int day() const { return _day; }
private:
int _year, _month, _day;
};
template <>
struct fmt::formatter<Date>
{
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.begin(); }
auto format(
const Date& date, format_context& ctx)
const -> decltype(ctx.out())
{
fmt::format_to(ctx.out(), "{}-{}-{}", date.year(), date.month(), date.day());
return ctx.out();
}
};
#define SHOW(expression) std::cout << #expression << " = \"" << expression << "\""<< std::endl;
int main(int argc, char** argv)
{
return 0;
}
std::string format(fmt::format_string< T... > pattern, T &&... args)
Format string.