build: Emulate std::to_string when it is missing

Change-Id: I4a08cf4abe7a2064a0c53d29582cbb761a1d131f
Refs: #2743
diff --git a/.waf-tools/compiler-features.py b/.waf-tools/compiler-features.py
index 5344939..774784d 100644
--- a/.waf-tools/compiler-features.py
+++ b/.waf-tools/compiler-features.py
@@ -18,10 +18,37 @@
 
 @conf
 def check_override(self):
-    if self.check_cxx(msg='Checking for override specifier',
-                      fragment=OVERRIDE,
-                      features='cxx', mandatory=False):
-        self.define('HAVE_CXX_OVERRIDE', 1)
+    self.check_cxx(msg='Checking for override specifier',
+                   fragment=OVERRIDE,
+                   define_name='HAVE_CXX_OVERRIDE',
+                   features='cxx', mandatory=False)
+
+STD_TO_STRING = '''
+#include <string>
+int
+main(int argc, char** argv)
+{
+  std::string s = std::to_string(0);
+  s = std::to_string(0l);
+  s = std::to_string(0ll);
+  s = std::to_string(0u);
+  s = std::to_string(0ul);
+  s = std::to_string(0ull);
+  s = std::to_string(0.0f);
+  s = std::to_string(0.0);
+  s = std::to_string(0.0l);
+  s.clear();
+  return 0;
+}
+'''
+
+@conf
+def check_std_to_string(self):
+    self.check_cxx(msg='Checking for std::to_string',
+                   fragment=STD_TO_STRING,
+                   define_name='HAVE_STD_TO_STRING',
+                   features='cxx', mandatory=False)
 
 def configure(conf):
     conf.check_override()
+    conf.check_std_to_string()
diff --git a/common.hpp b/common.hpp
index aac1580..ff9aa2a 100644
--- a/common.hpp
+++ b/common.hpp
@@ -57,6 +57,7 @@
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
+#include <string>
 
 #include <ndn-cxx/common.hpp>
 #include <ndn-cxx/interest.hpp>
@@ -110,4 +111,17 @@
 
 } // namespace nfd
 
+// Some platforms are missing std::to_string (issue #2743)
+#ifndef HAVE_STD_TO_STRING
+namespace std {
+template<typename V>
+inline std::string
+to_string(const V& v)
+{
+  return boost::lexical_cast<std::string>(v);
+}
+} // namespace std
+#endif // HAVE_STD_TO_STRING
+
+
 #endif // NFD_COMMON_HPP