This is an example showing various permutations of use of the FastFormat formatting API, with the
namespace suspended.
#ifndef FASTFORMAT_NO_NAMESPACE
# define FASTFORMAT_NO_NAMESPACE
#endif
#ifdef _AFXDLL
# include <afx.h>
#endif
#include <fastformat/sinks/ostream.hpp>
#ifdef __AFX_H__
# include <fastformat/sinks/CString.hpp>
#endif
#include <fastformat/fastformat.hpp>
#include <stlsoft/string/simple_string.hpp>
#include <platformstl/platformstl.hpp>
#ifdef __AFX_H__
#endif
#ifdef PLATFORMSTL_OS_IS_WINDOWS
# include <comstl/util/initialisers.hpp>
# include <comstl/util/variant.hpp>
#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** )
{
{
std::string sink;
char const* arg0 = "arg0";
std::string arg1 = "arg1";
#ifdef FASTFORMAT_NO_FILTER_TYPE_CONVERSION_SHIM_SUPPORT
char arg2[] = "10";
#else
int arg2 = 10;
#endif
sink.erase();
fmt(sink, "A c-style string: {0}", arg0);
sink.erase();
fmt(sink, "A std::string: {0}", arg1);
sink.erase();
fmt(sink, "A c-style string: {0}, and a std::string: {1}", arg0, arg1);
sink.erase();
fmt(sink, "A c-style string: {1}, and an int: {0}", arg2, arg0);
}
{
stlsoft::simple_string sink;
std::string fmt0("A c-style string: {0}");
std::string fmt1("A std::string: {0}");
std::string fmt2("A c-style string: {0}, and a std::string: {1}");
std::string fmt3("A c-style string: {1}, and an int: {0}");
char const* arg0 = "arg0";
std::string arg1 = "arg1";
#ifdef FASTFORMAT_NO_FILTER_TYPE_CONVERSION_SHIM_SUPPORT
char arg2[] = "10";
#else
int arg2 = 10;
#endif
sink.clear();
fmt(sink, fmt0, arg0);
sink.clear();
fmt(sink, fmt1, arg1);
sink.clear();
fmt(sink, fmt2, arg0, arg1);
sink.clear();
fmt(sink, fmt3, arg2, arg0);
}
{
std::ostream& sink = std::cout;
std::string fmt0("A c-style string: {0}");
std::string fmt1("A std::string: {0}");
std::string fmt2("A c-style string: {0}, and a std::string: {1}");
std::string fmt3("A c-style string: {1}, and an int: {0}");
char const* arg0 = "arg0";
std::string arg1 = "arg1";
#ifdef FASTFORMAT_NO_FILTER_TYPE_CONVERSION_SHIM_SUPPORT
char arg2[] = "10";
#else
int arg2 = 10;
#endif
sink.clear();
fmtln(sink, fmt0, arg0);
sink.clear();
fmtln(sink, fmt1, arg1);
sink.clear();
fmtln(sink, fmt2, arg0, arg1);
sink.clear();
fmtln(sink, fmt3, arg2, arg0);
}
#ifdef __AFX_H__
{
CString sink;
stlsoft::simple_string fmt0("A c-style string: {0}");
stlsoft::simple_string fmt1("A stlsoft::simple_string: {0}");
stlsoft::simple_string fmt2("A c-style string: {0}, and a stlsoft::simple_string: {1}");
stlsoft::simple_string fmt3("A c-style string: {1}, and an int: {0}");
char const* arg0 = "arg0";
CString arg1 = "arg1";
#ifdef FASTFORMAT_NO_FILTER_TYPE_CONVERSION_SHIM_SUPPORT
char arg2[] = "10";
#else
int arg2 = 10;
#endif
sink.Empty();
fmt(sink, fmt0, arg0);
sink.Empty();
fmt(sink, fmt1, arg1);
sink.Empty();
fmt(sink, fmt2, arg0, arg1);
sink.Empty();
fmt(sink, fmt3, arg2, arg0);
}
#endif
#ifdef PLATFORMSTL_OS_IS_WINDOWS
{
std::ostream& sink = std::cout;
comstl::variant fmt0( "A c-style string: {0}");
comstl::variant fmt1(L"A VARIANT: {0}");
comstl::variant fmt2( "A c-style string: {0}, and a VARIANT: {1}");
comstl::variant fmt3(L"A c-style string: {1}, and an unsigned short: {0}");
char const* arg0 = "arg0";
comstl::variant arg1 = "arg1";
#ifdef FASTFORMAT_NO_FILTER_TYPE_CONVERSION_SHIM_SUPPORT
char arg2[] = "10";
#else
unsigned short arg2 = 10;
#endif
fmt(sink, fmt0, arg0);
fmt(sink, fmt1, arg1);
fmt(sink, fmt2, arg0, arg1);
fmt(sink, fmt3, arg2, arg0);
}
#endif
return EXIT_SUCCESS;
}
int main(int argc, char** argv)
{
try
{
#ifdef PLATFORMSTL_OS_IS_WINDOWS
comstl::com_initialiser coinit;
#endif
return main_(argc, argv);
}
catch(std::exception& x)
{
cerr << "Unhandled error: " << x.what() << endl;
}
catch(...)
{
cerr << "Unhandled unknown error" << endl;
}
return EXIT_FAILURE;
}
#ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
# if defined(_DEBUG) && \
defined(STLSOFT_COMPILER_IS_MSVC)
# include <fastformat/sinks/auto_buffer.hpp>
# include <fastformat/sinks/c_string.hpp>
# include <fastformat/sinks/char_buffer.hpp>
# ifdef __AFX_H__
# include <fastformat/sinks/CString.hpp>
# endif
# include <fastformat/sinks/FILE.hpp>
# include <fastformat/sinks/ostream.hpp>
# if defined(WIN32) || \
defined(WIN64)
# include <fastformat/sinks/CComBSTR.hpp>
# include <fastformat/sinks/speech.hpp>
# endif
# include <fastformat/sinks/stringstream.hpp>
# if _MSC_VER == 1200 && \
defined(UNIX)
# include <fastformat/sinks/vectored_file.hpp>
# endif
# endif
#endif