Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
fmt.hh File Reference
#include <iostream>
#include <string>
#include <boost/format.hpp>
#include "lix/libutil/ansicolor.hh"

Go to the source code of this file.

Classes

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

Functions

std::string nix::getStackTrace ()
template<class T>
std::ostream & nix::operator<< (std::ostream &out, const Magenta< T > &y)
template<class T>
std::ostream & nix::operator<< (std::ostream &out, const Uncolored< T > &y)
void nix::fmt_internal::setExceptions (boost::format &fmt)
std::string nix::fmt (const std::string &s)
std::string nix::fmt (const char *s)
template<typename... Args>
std::string nix::fmt (const std::string &fs, const Args &... args)
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.

◆ getStackTrace()

std::string nix::getStackTrace ( )

Gets a C++ stack trace using boost stacktrace

◆ setExceptions()

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

Set the correct exceptions for fmt.