search for: format_provid

Displaying 4 results from an estimated 4 matches for "format_provid".

Did you mean: format_provider
2016 Oct 12
2
RFC: General purpose type-safe formatting library
...ent over traditional formatting > mechanisms. If you pass an object for which it cannot find a formatter, it > fails to compile. > > However, you can always define custom formatters for your own types. If > you write: > > namespace llvm { > template<> > struct format_provider<Foo> { > static void format(raw_ostream &S, const Foo &F, int Align, StringRef > Options) { > } > }; > } > > Then #6 will magically compile, and invoke the function above to do the > formatting. There are other ways to customize the formatting beha...
2016 Oct 12
15
RFC: General purpose type-safe formatting library
...le! Here is another example of an improvement over traditional formatting mechanisms. If you pass an object for which it cannot find a formatter, it fails to compile. However, you can always define custom formatters for your own types. If you write: namespace llvm { template<> struct format_provider<Foo> { static void format(raw_ostream &S, const Foo &F, int Align, StringRef Options) { } }; } Then #6 will magically compile, and invoke the function above to do the formatting. There are other ways to customize the formatting behavior, but I'll keep going with some...
2016 Oct 31
0
RFC: General purpose type-safe formatting library
...if the type cannot be formatted. struct Foo {}; outs() << "{0}"_fmt.stream(Foo{}); // compilation failure. 8) Extensible format provider mechanism to allow formatting of your own types. struct AddressRange { uint64_t Begin; uint64_t End; } template<> class format_provider<AddressRange> { public: static void format(const AddressRange &R, raw_ostream &S, StringRef Style) { S << "[{0:X} - {1:X}]"_fmt.stream(R.begin(), R.end()); } }; AddressRange AR{0, 0xDEADBEEF}; outs() << "{0}&quot...
2016 Oct 14
2
RFC: General purpose type-safe formatting library
On 12.10.2016 05:59, Mehdi Amini via llvm-dev wrote: >> If you change a const char * to a StringRef, it can silently succeed >> while passing your StringRef object to printf. It should fail to compile! > > llvm::format now fails to compile as well :) > > However this does not address other issues, like: `format(ā€œ%dā€, float_var)` This may be a good time to point at