aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-04-17 17:55:46 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-04-17 17:55:46 +0000
commitc3af10b1593a472aacd141cb3aa6143c79d92da2 (patch)
tree7835231ad79127040f77cac54c04f88fdb70875f
parent193a5fc1def667d54a3f502fe095f825d20ac9ee (diff)
downloadpaludis-c3af10b1593a472aacd141cb3aa6143c79d92da2.tar.gz
paludis-c3af10b1593a472aacd141cb3aa6143c79d92da2.tar.xz
Fix inquisitio.
-rw-r--r--paludis/package_database.cc4
-rw-r--r--paludis/util/stringify.hh131
2 files changed, 62 insertions, 73 deletions
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index 1c878bd..ae6f2dc 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -110,8 +110,8 @@ AmbiguousPackageNameError::AmbiguousPackageNameError(const std::string & our_nam
_name_data(new NameData)
{
_name_data->name = our_name;
- while (begin != end)
- _name_data->names.push_back(stringify(*begin++));
+ std::transform(begin, end, std::back_inserter(_name_data->names),
+ &stringify<typename std::iterator_traits<I_>::value_type>);
}
AmbiguousPackageNameError::AmbiguousPackageNameError(const AmbiguousPackageNameError & other) :
diff --git a/paludis/util/stringify.hh b/paludis/util/stringify.hh
index cad30dc..6fe00bb 100644
--- a/paludis/util/stringify.hh
+++ b/paludis/util/stringify.hh
@@ -112,95 +112,84 @@ namespace paludis
}
#endif
- /**
- * Convert item to a string.
- *
- * \ingroup g_strings
- */
- template <typename T_>
+ template <typename T_> inline std::string stringify(const T_ & item);
+
+ namespace stringify_internals
+ {
+ /**
+ * Internal function to convert item to a string, to make
+ * function pointers work more sensibly. May be overloaded,
+ * but should not be called directly.
+ *
+ * \ingroup g_strings
+ */
+ template <typename T_>
#ifdef PALUDIS_HAVE_CONCEPTS
- requires IsStreamStringifiable<T_>
+ requires IsStreamStringifiable<T_>
#endif
- std::string
- stringify(const T_ & item)
- {
+ std::string
+ real_stringify(const T_ & item)
+ {
#ifndef PALUDIS_HAVE_CONCEPTS
- /* check that we're not trying to stringify a pointer or somesuch */
- int check_for_stringifying_silly_things
- PALUDIS_ATTRIBUTE((unused)) = stringify_internals::CheckType<T_>::value;
+ /* check that we're not trying to stringify a pointer or somesuch */
+ int check_for_stringifying_silly_things
+ PALUDIS_ATTRIBUTE((unused)) = CheckType<T_>::value;
#endif
- std::ostringstream s;
- s << item;
- return s.str();
- }
+ std::ostringstream s;
+ s << item;
+ return s.str();
+ }
- /**
- * Convert item to a string (overload for std::string).
- *
- * \ingroup g_strings
- */
- inline std::string
- stringify(const std::string & item)
- {
- return item;
- }
+ inline std::string
+ real_stringify(const std::string & item)
+ {
+ return item;
+ }
- /**
- * Convert item to a string (overload for char).
- *
- * \ingroup g_strings
- */
- inline std::string
- stringify(const char & item)
- {
- return std::string(1, item);
- }
+ inline std::string
+ real_stringify(const char & item)
+ {
+ return std::string(1, item);
+ }
- /**
- * Convert item to a string (overload for unsigned char).
- *
- * \ingroup g_strings
- */
- inline std::string
- stringify(const unsigned char & item)
- {
- return std::string(1, item);
- }
+ inline std::string
+ real_stringify(const unsigned char & item)
+ {
+ return std::string(1, item);
+ }
- /**
- * Convert item to a string (overload for bool).
- *
- * \ingroup g_strings
- */
- inline std::string
- stringify(const bool & item)
- {
- return item ? "true" : "false";
- }
+ inline std::string
+ real_stringify(const bool & item)
+ {
+ return item ? "true" : "false";
+ }
- /**
- * Convert item to a string (overload for char *, which isn't a
- * screwup like other pointers).
- *
- * \ingroup g_strings
- */
- inline std::string
- stringify(const char * const item)
- {
- return std::string(item);
+ inline std::string
+ real_stringify(const char * const item)
+ {
+ return std::string(item);
+ }
+
+ template <typename D_, typename V_, bool c_, typename C_>
+ inline std::string
+ real_stringify(const Validated<D_, V_, c_, C_> & v)
+ {
+ return stringify(v.data());
+ }
}
/**
- * Convert item to a string (overload for Validated).
+ * Convert item to a string. To customise for new types, overload
+ * stringify_internals::real_stringify, not this function.
*
* \ingroup g_strings
*/
- template <typename D_, typename V_, bool c_, typename C_>
+ template <typename T_>
inline std::string
- stringify(const Validated<D_, V_, c_, C_> & v)
+ stringify(const T_ & item)
{
- return stringify(v.data());
+ return stringify_internals::real_stringify(item);
}
}