examples/example.arguments.reals/example.arguments.reals.cpp
This is an example showing how to use the floating-point conversion shims that come with Pantheios, but that are not included by default.
#include <fastformat/sinks/ostream.hpp>
#include <fastformat/shims/conversion/filter_type/reals.hpp>
#include <fastformat/fastformat.hpp>
#ifdef FASTFORMAT_NO_FILTER_TYPE_CONVERSION_SHIM_SUPPORT
# error Cannot compile this file with a compiler that does not support the filter_type mechanism
#endif
#include <exception>
#include <iostream>
#include <string>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
#include <stdlib.h>
static int main_(int , char** )
{
const float flt = 1.2345f;
const double dbl = -123E-45;
#ifdef FASTFORMAT_USE_WIDE_STRINGS
fastformat::fmtln(std::wcout, L"a float={0}", flt);
fastformat::fmtln(std::wcout, L"a double={0}", dbl);
fastformat::writeln(std::wcout, L"a float=", flt);
fastformat::writeln(std::wcout, L"a double=", dbl);
#else
fastformat::fmtln(std::cout, "a float={0}", flt);
fastformat::fmtln(std::cout, "a double={0}", dbl);
fastformat::writeln(std::cout, "a float=", flt);
fastformat::writeln(std::cout, "a double=", dbl);
#endif
#ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
if(0)
{
const int i = -123;
# ifdef FASTFORMAT_USE_WIDE_STRINGS
fastformat::fmtln(std::wcout, L"an integer={0}", i);
# else
fastformat::fmtln(std::cout, "an integer={0}", i);
# endif
}
#endif
return EXIT_SUCCESS;
}
int main(int argc, char** argv)
{
try
{
return main_(argc, argv);
}
catch(std::exception& x)
{
cerr << "Unhandled error: " << x.what() << endl;
}
catch(...)
{
cerr << "Unhandled unknown error" << endl;
}
return EXIT_FAILURE;
}