Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
fmt.hh File Reference
#include <boost/format.hpp>
#include <string>
#include <filesystem>
#include "nix/util/ansicolor.hh"

Go to the source code of this file.

Classes

struct  nix::Magenta< T >
struct  nix::PathFmt
struct  nix::Uncolored< T >
class  nix::HintFmt

Functions

template<class F>
void nix::formatHelper (F &f)
template<class F, typename T, typename... Args>
void nix::formatHelper (F &f, const T &x, const Args &... args)
void nix::setExceptions (boost::format &fmt)
std::string nix::fmt (const std::string &s)
std::string nix::fmt (std::string_view s)
std::string nix::fmt (const char *s)
template<typename... Args>
std::string nix::fmt (const std::string &fs, const Args &... args)
template<class T>
std::ostream & nix::operator<< (std::ostream &out, const Magenta< T > &y)
std::ostream & nix::operator<< (std::ostream &out, const PathFmt &y)
template<class T>
std::ostream & nix::operator<< (std::ostream &out, const Uncolored< T > &y)
std::ostream & nix::operator<< (std::ostream &os, const HintFmt &hf)

Function Documentation

◆ fmt()

std::string nix::fmt ( const std::string & s)
inline

A helper for writing a boost::format expression to a string.

These are (roughly) equivalent:

fmt(formatString, a_0, ..., a_n)
(boost::format(formatString) % a_0 % ... % a_n).str()

However, when called with a single argument, the string is returned unchanged.

If you write code like this:

std::cout << boost::format(stringFromUserInput) << std::endl;

And stringFromUserInput contains formatting placeholders like s, then the code will crash at runtime. fmt helps you avoid this pitfall.

◆ formatHelper()

template<class F>
void nix::formatHelper ( F & f)
inline

A helper for writing boost::format expressions.

These are equivalent:

formatHelper(formatter, a_0, ..., a_n)
formatter % a_0 % ... % a_n

With a single argument, formatHelper(s) is a no-op.

◆ setExceptions()

void nix::setExceptions ( boost::format & fmt)
inline

Set the correct exceptions for fmt.