Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.37 KB

README.md

File metadata and controls

49 lines (35 loc) · 1.37 KB

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