fmtlib支持 range的基本语法:
range_format_spec ::= [":" [underlying_spec]]
underlying_spec是基于范围引用类型的格式化程序进行解析的。
测试代码:
#include <iostream>
#include <vector>
#include <fmt/ranges.h>
using namespace std;
int main(int argc, char** argv)
{
string x;
x = fmt::format("{}", std::vector<int>{ 10, 20, 30 });
cout << x << endl;
// Result: [10, 20, 30]
x = fmt::format("{::#x}", std::vector<int>{ 10, 20, 30 });
cout << x << endl;
// Result: [0xa, 0x14, 0x1e]
x = fmt::format("{}", vector<char>{ 'h', 'e', 'l', 'l', 'o' });
cout << x << endl;
// Result: ['h', 'e', 'l', 'l', 'o']
x = fmt::format("{::}", vector<char>{ 'h', 'e', 'l', 'l', 'o' });
cout << x << endl;
// Result: [h, e, l, l, o]
x = fmt::format("{::d}", vector<char>{ 'h', 'e', 'l', 'l', 'o' });
cout << x << endl;
// Result: [104, 101, 108, 108, 111]
return 0;
}
运行结果: