aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-28 07:00:10 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-28 07:00:10 +0000
commitceb546a75826c916aa33061c805ed6cf7e375a90 (patch)
tree1a70b814f4bbc9319d2d0b0a7d795eb3c6e555fb
parent4d2b4b9f631cea8744b56b44adf3cf05d9e0c3aa (diff)
downloadpaludis-ceb546a75826c916aa33061c805ed6cf7e375a90.tar.gz
paludis-ceb546a75826c916aa33061c805ed6cf7e375a90.tar.xz
Overload rather than specialise for stringify. Catch stringify(non-char pointer) mistakes at compile time.
-rw-r--r--paludis/stringify.hh39
1 files changed, 27 insertions, 12 deletions
diff --git a/paludis/stringify.hh b/paludis/stringify.hh
index 9910c8c..82b38cc 100644
--- a/paludis/stringify.hh
+++ b/paludis/stringify.hh
@@ -42,44 +42,59 @@ namespace paludis
}
/**
- * Convert item to a string (specialisation for std::string).
+ * Convert item to a string (overload for std::string).
*/
- template <>
inline std::string
- stringify<std::string>(const std::string & item)
+ stringify(const std::string & item)
{
return item;
}
/**
- * Convert item to a string (specialisation for char).
+ * Convert item to a string (overload for char).
*/
- template <>
inline std::string
- stringify<char>(const char & item)
+ stringify(const char & item)
{
return std::string(1, item);
}
/**
- * Convert item to a string (specialisation for unsigned char).
+ * Convert item to a string (overload for unsigned char).
*/
- template <>
inline std::string
- stringify<unsigned char>(const unsigned char & item)
+ stringify(const unsigned char & item)
{
return std::string(1, item);
}
/**
- * Convert item to a string (specialisation for bool).
+ * Convert item to a string (overload for bool).
*/
- template <>
inline std::string
- stringify<bool>(const bool & item)
+ stringify(const bool & item)
{
return item ? "true" : "false";
}
+
+ /**
+ * Convert item to a string (undefined overload for pointers, to
+ * catch screwups at compiletime rather than printing out addresses in
+ * weird places because of a missing *).
+ */
+ template <typename T_>
+ void
+ stringify(const T_ * const item);
+
+ /**
+ * Convert item to a string (overload for char *, which isn't a
+ * screwup like other pointers).
+ */
+ inline std::string
+ stringify(const char * const item)
+ {
+ return std::string(item);
+ }
}
#endif