22 #ifndef GEARS_IO_FPRINT_HPP
23 #define GEARS_IO_FPRINT_HPP
25 #include "detail/index_printer.hpp"
26 #include "../string/classification.hpp"
113 template<
class Elem,
class Traits,
typename... Args>
114 inline void fprint(std::basic_ostream<Elem, Traits>& out,
const std::basic_string<Elem, Traits>& str, Args&&... arguments) {
115 if(
sizeof...(arguments) < 1) {
120 auto args = std::make_tuple(std::forward<Args>(arguments)...);
123 auto&& length = str.size();
124 auto&& original_width = out.width();
125 std::ios_base::fmtflags original_format = out.flags();
126 auto&& original_precision = out.precision();
128 for(decltype(str.size()) i = 0; i < length; ++i) {
131 if(c != out.widen(
'{')) {
146 decltype(out.width()) width = 0;
147 decltype(out.precision()) precision = 0;
148 auto format = original_format;
151 if(str[j] == out.widen(
'{')) {
162 index = (index * 10) + (str[j++] - out.widen(
'0'));
164 while(j < length && cmp(str[j]));
168 throw std::runtime_error(
"invalid format string specified");
172 if(str[j] == out.widen(
',')) {
176 if(str[j + 1] == out.widen(
'-')) {
186 if(j < length && cmp(str[j])) {
189 width = (width * 10) + (str[j++] - out.widen(
'0'));
191 while(j < length && cmp(str[j]));
195 throw std::runtime_error(
"invalid format string specified");
202 if(str[j] == out.widen(
':')) {
205 auto&& specifier = str[j + 1];
211 format = (format & ~out.basefield) | out.oct;
214 format = (format & ~out.basefield) | out.hex;
217 format = (format & ~out.basefield) | out.hex | out.uppercase;
220 format |= out.scientific | out.uppercase;
223 format |= out.scientific;
226 format |= out.boolalpha;
229 format |= out.showpos;
232 throw std::runtime_error(
"no such format specifier found");
238 if(j < length && cmp(str[j])) {
240 precision = (precision * 10) + (str[j++] - out.widen(
'0'));
242 while(j < length && cmp(str[j]));
248 if(str[j] == out.widen(
'}')) {
251 out.precision(precision);
252 detail::index_printer(out, index, args);
253 out.width(original_width);
254 out.flags(original_format);
255 out.precision(original_precision);
263 #endif // GEARS_IO_FPRINT_HPP