examples/example.arguments.character/example.arguments.character.cpp
This is an example showing how an argument conversion shim might be implemented for the
char
type.
#include <fastformat/fastformat.h>
#include <fastformat/sinks/ostream.hpp>
#include <exception>
#include <iostream>
#include <string>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
#include <stdlib.h>
#if !defined(FASTFORMAT_NO_NAMESPACE)
namespace fastformat
{
namespace filters
{
#endif
#if 1
inline std::basic_string<ff_char_t> filter_type(char value, char const*, ff_char_t const volatile*)
{
return std::basic_string<ff_char_t>(1u, value);
}
#else
inline ff_string_slice_t filter_type(char const& value, char const*, ff_char_t const volatile*)
{
ff_string_slice_t result;
result.len = 1;
result.ptr = &value;
return result;
}
#endif
#if !defined(FASTFORMAT_NO_NAMESPACE)
}
}
#endif
#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
static int main_(int , char** )
{
#ifdef FASTFORMAT_USE_WIDE_STRINGS
# define stm std::wcout
#else
# define stm std::cout
#endif
const char c1 = '~';
fastformat::fmtln(stm, FASTFORMAT_LITERAL_STRING("c1={0}"), c1);
fastformat::writeln(stm, FASTFORMAT_LITERAL_STRING("c1="), c1);
#if 0
const wchar_t c2 = L'#';
fastformat::fmtln(stm, FASTFORMAT_LITERAL_STRING("c2={0}"), c2);
fastformat::writeln(stm, FASTFORMAT_LITERAL_STRING("c2="), c2);
#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;
}