Compile-time Checked, Type-Safe Formatting in C++14
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
3rdparty
cmake
include/mpark
test
.gitignore
.gitmodules
CMakeLists.txt
LICENSE_1_0.txt
README.md

README.md

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