]> git.lyx.org Git - lyx.git/blobdiff - src/support/tostr.h
tostr -> convert and some bformat work
[lyx.git] / src / support / tostr.h
index 931afa3163b689f553268dc42b2344c3f2d646de..93e1f9a943cedb10831a7459bc39e485751ad9bf 100644 (file)
@@ -5,6 +5,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author André Pönitz
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  *
 #ifndef TOSTR_H
 #define TOSTR_H
 
-#include "LString.h"
-
-// When trying to convert this to a template using std::stringstream,
-// note that this will pull in the whole of <string> in more than 150
-// files, even when configuring --with-included-strings !
-
-/// convert things to strings
-string const tostr(bool b);
-///
-string const tostr(int);
-///
-string const tostr(unsigned int);
-///
-string const tostr(long int);
-///
-string const tostr(double);
-///
-string const tostr(string const & s);
+#include <boost/static_assert.hpp>
+
+#include <string>
+
+template <class Target, class Source>
+Target convert(Source arg)
+{
+       // We use a static assert here since we want all instances of
+       // this template to be specializations.
+       BOOST_STATIC_ASSERT(sizeof(bool) == 0);
+       return Target();
+}
+
+template<>
+std::string convert<std::string>(bool);
+
+template<>
+std::string convert<std::string>(char);
+
+template<>
+std::string convert<std::string>(unsigned short);
+
+template<>
+std::string convert<std::string>(int);
+
+template<>
+std::string convert<std::string>(unsigned int);
+
+template<>
+std::string convert<std::string>(float);
+
+template<>
+std::string convert<std::string>(double);
+
+template<>
+std::string convert<std::string>(std::string);
 
 #endif