format: add '!' coercion format specifier

using in place of the format '!' will force a type coercion to string
before rendering.
This commit is contained in:
Danny Robson 2016-02-02 16:49:45 +11:00
parent 9cb25456a4
commit 4ac0139657

View File

@ -32,56 +32,56 @@ namespace util {
///////////////////////////////////////////////////////////////////////
template <typename T>
inline bool
is_valid_specifier (const char*)
is_type_specifier (const char*)
{ return false; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<const char*> (const char *s)
is_type_specifier<const char*> (const char *s)
{ return *s == 's'; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<char*> (const char *s)
is_type_specifier<char*> (const char *s)
{ return *s == 's'; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<std::string> (const char *s)
is_type_specifier<std::string> (const char *s)
{ return *s == 's'; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<boost::filesystem::path> (const char *s)
is_type_specifier<boost::filesystem::path> (const char *s)
{ return *s == 's'; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<size_t> (const char *s)
is_type_specifier<size_t> (const char *s)
{ return *s == 'u'; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<unsigned> (const char *s)
is_type_specifier<unsigned> (const char *s)
{ return *s == 'u'; }
//---------------------------------------------------------------------
template <>
inline bool
is_valid_specifier<float> (const char *s)
is_type_specifier<float> (const char *s)
{
switch (*s) {
case 'e':
@ -100,6 +100,15 @@ namespace util {
}
///////////////////////////////////////////////////////////////////////
template <typename T>
inline bool
is_valid_specifier (const char *s)
{
return *s == '!' || is_type_specifier<T> (s);
}
///////////////////////////////////////////////////////////////////////
template <typename InputIt>
void