Skip to content

mpark/format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPark.Format

Compile-time Checked, Type-Safe Formatting in C++14.

stability license wandbox

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.

#include <iostream>
#include <ostream>

#include <mpark/format.hpp>

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."
}

About

Compile-time Checked, Type-Safe Formatting in C++14

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published