https://github.com/mpark/format
Compile-time Checked, Type-Safe Formatting in C++14
https://github.com/mpark/format
Last synced: 3 months ago
JSON representation
Compile-time Checked, Type-Safe Formatting in C++14
- Host: GitHub
- URL: https://github.com/mpark/format
- Owner: mpark
- License: bsl-1.0
- Created: 2014-08-10T16:40:21.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-04-19T21:13:48.000Z (about 9 years ago)
- Last Synced: 2025-04-04T16:28:59.549Z (about 1 year ago)
- Language: C++
- Homepage:
- Size: 20.5 KB
- Stars: 36
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE_1_0.txt
Awesome Lists containing this project
README
# MPark.Format
> Compile-time Checked, Type-Safe Formatting in __C++14__.
[![stability][badge.stability]][stability]
[![license][badge.license]][license]
[![wandbox][badge.wandbox]][wandbox]
[badge.stability]: https://img.shields.io/badge/stability-experimental-orange.svg
[badge.license]: http://img.shields.io/badge/license-boost-blue.svg
[badge.wandbox]: https://img.shields.io/badge/try%20it-on%20wandbox-green.svg
[stability]: http://github.com/badges/stability-badges
[license]: https://github.com/mpark/patterns/blob/master/LICENSE_1_0.txt
[wandbox]: https://wandbox.org/permlink/NfSCfnToS2QCJy36
## Introduction
__MPark.Format__ is an experimental compile-time checked, type-safe formatting
library for __C++14__.
Currently, it supports Python-like format strings with positional parameters.
```cpp
#include
#include
#include
struct Date {
int year, month, day;
};
std::ostream &operator<<(std::ostream &strm, const Date &that) {
return strm << mpark::format(
FS("{0}-{1}-{2}"), that.year, that.month, that.day);
}
int main() {
std::cout << mpark::format(FS("{0}{1}{0}\n"), "abra", "cad");
// prints: "abracadabra"
// std::cout << mpark::format(FS("{0}, {1}\n"), 'x');
// error: Index out of range.
std::cout << mpark::format(FS("The date is {0}.\n"), Date{2016, 4, 19});
// prints: "The date is 2016-4-19."
}
```