define explicit specialisations for primitive types

This commit is contained in:
Fischlurch 2011-12-30 05:13:27 +01:00
parent e054c272b6
commit 0d136e2703
4 changed files with 51 additions and 21 deletions

View file

@ -103,18 +103,38 @@ namespace util {
pushParameter(string("(null)"));
}
template<>
void
_Fmt::pushParameter (const char * const cString)
{
pushParameter (cString);
}
/* ===== explicitly supported =================== */
template void _Fmt::pushParameter(string const&);
template void _Fmt::pushParameter(char const&);
template void _Fmt::pushParameter(uchar const&);
template void _Fmt::pushParameter(int const&);
template void _Fmt::pushParameter(uint const&);
template void _Fmt::pushParameter(short const&);
template void _Fmt::pushParameter(ushort const&);
template void _Fmt::pushParameter(int64_t const&);
template void _Fmt::pushParameter(uint64_t const&);
template void _Fmt::pushParameter(float const&);
template void _Fmt::pushParameter(double const&);
template void _Fmt::pushParameter(void * const&);
template void _Fmt::pushParameter(const string * const);
template void _Fmt::pushParameter(const uchar * const);
template void _Fmt::pushParameter(const int * const);
template void _Fmt::pushParameter(const uint * const);
template void _Fmt::pushParameter(const short * const);
template void _Fmt::pushParameter(const ushort * const);
template void _Fmt::pushParameter(const int64_t * const);
template void _Fmt::pushParameter(const uint64_t * const);
template void _Fmt::pushParameter(const float * const);
template void _Fmt::pushParameter(const double * const);

View file

@ -71,10 +71,11 @@ namespace std { // forward declaration to avoid including <iostream>
namespace util {
typedef unsigned char uchar;
using boost::enable_if;
using std::string;
@ -173,17 +174,25 @@ namespace util {
/* the following definitions enable some basic types
* to be forwarded to boost::format literally */
template<> struct _shall_forward<string> { enum{ value = true }; };
template<> struct _shall_forward<char> { enum{ value = true }; };
template<> struct _shall_forward<uchar> { enum{ value = true }; };
template<> struct _shall_forward<int> { enum{ value = true }; };
template<> struct _shall_forward<uint> { enum{ value = true }; };
template<> struct _shall_forward<short> { enum{ value = true }; };
template<> struct _shall_forward<ushort> { enum{ value = true }; };
template<> struct _shall_forward<int64_t> { enum{ value = true }; };
template<> struct _shall_forward<uint64_t>{ enum{ value = true }; };
template<> struct _shall_forward<float> { enum{ value = true }; };
template<> struct _shall_forward<double> { enum{ value = true }; };
template<> struct _shall_forward<void*> { enum{ value = true }; };
template<typename X>
struct _shall_convert_toString
{
enum{ value = ! _shall_forward<X>::value
&& lib::meta::_can_convertToString<X>::value
&& lib::meta::can_convertToString<X>::value
&& !lib::meta::is_sameType<X,char*>::value
};
};

View file

@ -75,7 +75,7 @@ namespace meta {
* @see string-util.hpp more elaborate solution including lexical_cast
*/
template<typename T>
struct _can_convertToString
struct can_convertToString
{
static T & probe();

View file

@ -89,8 +89,9 @@ namespace test {
_Fmt formatter (formatString);
uint val = rand() % 100;
void *pt = &val;
formatter % &val;
formatter % &pt;
formatter % val;
cout << formatter << endl;
@ -102,7 +103,7 @@ namespace test {
{
int i(-12);
CHECK (_Fmt("%d") % i == "-12" );
CHECK (_Fmt("%6d") % i == "- 12" );
CHECK (_Fmt("%6d") % i == " -12" );
CHECK (_Fmt("%-6d") % i == "-12 " );
CHECK (_Fmt("%+-6d") % -i == "+12 " );
CHECK (_Fmt("%+06d") % -i == "+00012" );
@ -242,8 +243,8 @@ namespace test {
verify_errorHandling ()
{
cout << _Fmt("__nix_") % 1 % 2 << endl;
cout << _Fmt("__%d__") << endl;
cout << _Fmt("__%d__") % 1 << endl;
cout << _Fmt("__%d__") << endl;
cout << _Fmt("__%d__") % 1 << endl;
cout << _Fmt("__%d__") % 1 % 2 << endl;
cout << _Fmt("__%d__") % "dirt" << endl;
@ -255,19 +256,19 @@ namespace test {
void
verify_pointerHandling ()
{
int i(-12); int * pi = & i;
uint u(12); uint * pu = & u;
short sh(-123); short * psh = & sh;
ushort ush(123); ushort *push = &ush;
long l(-123); long * pl = & l;
ulong ul(123); ulong * pul = & ul;
int64_t ll(5e+9); int64_t * pll = & ll;
uint64_t ull(ll); uint64_t *pull = &ull;
float f(12.34); float * pf = & f;
double d(-12.34); double * pd = & d;
char c(0x40); char * pc = & c;
unsigned char uc(0xff); unsigned char * puc = & uc;
string str("Lumiera"); string *pstr = &str;
int i(-12); int * pi = & i;
uint u(12); uint * pu = & u;
short sh(-123); short * psh = & sh;
ushort ush(123); ushort * push = &ush;
long l(-123); long * pl = & l;
ulong ul(123); ulong * pul = & ul;
int64_t ll(5e+9); int64_t * pll = & ll;
uint64_t ull(ll); uint64_t * pull = &ull;
float f(12.34); float * pf = & f;
double d(-12.34); double * pd = & d;
char c(0x40); char * pc = & c;
uchar uc(0xff); uchar * puc = & uc;
string str("Lumiera"); string * pstr = &str;
CHECK (_Fmt("%d") % i == _Fmt("%d") % pi);
CHECK (_Fmt("%d") % u == _Fmt("%d") % pu);