Add setPort() to folly::URI class.
[folly.git] / folly / String.h
index 93a4c658363c145046bc5c83f80e20de2d7e0a94..241d4dbf6aac26479d88853cf3514a4f99eac137 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <string>
 #include <boost/type_traits.hpp>
 
-#ifdef __GNUC__
-# include <ext/hash_set>
-# include <ext/hash_map>
+#ifdef _GLIBCXX_SYMVER
+#include <ext/hash_set>
+#include <ext/hash_map>
 #endif
 
+#include <unordered_set>
+#include <unordered_map>
+
 #include "folly/Conv.h"
+#include "folly/Demangle.h"
 #include "folly/FBString.h"
 #include "folly/FBVector.h"
+#include "folly/Portability.h"
 #include "folly/Range.h"
 #include "folly/ScopeGuard.h"
 
@@ -313,22 +318,6 @@ std::string hexDump(const void* ptr, size_t size);
  */
 fbstring errnoStr(int err);
 
-/**
- * Return the demangled (prettyfied) version of a C++ type.
- *
- * This function tries to produce a human-readable type, but the type name will
- * be returned unchanged in case of error or if demangling isn't supported on
- * your system.
- *
- * Use for debugging -- do not rely on demangle() returning anything useful.
- *
- * This function may allocate memory (and therefore throw).
- */
-fbstring demangle(const char* name);
-inline fbstring demangle(const std::type_info& type) {
-  return demangle(type.name());
-}
-
 /**
  * Debug string for an exception: include type and what().
  */
@@ -443,6 +432,13 @@ void join(const Delim& delimiter,
   join(delimiter, container.begin(), container.end(), output);
 }
 
+template <class Delim, class Value, class String>
+void join(const Delim& delimiter,
+          const std::initializer_list<Value>& values,
+          String& output) {
+  join(delimiter, values.begin(), values.end(), output);
+}
+
 template <class Delim, class Container>
 std::string join(const Delim& delimiter,
                  const Container& container) {
@@ -451,19 +447,34 @@ std::string join(const Delim& delimiter,
   return output;
 }
 
+template <class Delim, class Value>
+std::string join(const Delim& delimiter,
+                 const std::initializer_list<Value>& values) {
+  std::string output;
+  join(delimiter, values.begin(), values.end(), output);
+  return output;
+}
+
 } // namespace folly
 
-// Hash functions for string and fbstring usable with e.g. hash_map
-#ifdef __GNUC__
-namespace __gnu_cxx {
+// Hash functions to make std::string usable with e.g. hash_map
+//
+// Handle interaction with different C++ standard libraries, which
+// expect these types to be in different namespaces.
+namespace std {
 
 template <class C>
-struct hash<folly::basic_fbstring<C> > : private hash<const C*> {
-  size_t operator()(const folly::basic_fbstring<C> & s) const {
+struct hash<std::basic_string<C> > : private hash<const C*> {
+  size_t operator()(const std::basic_string<C> & s) const {
     return hash<const C*>::operator()(s.c_str());
   }
 };
 
+}
+
+#if defined(_GLIBCXX_SYMVER) && !defined(__BIONIC__)
+namespace __gnu_cxx {
+
 template <class C>
 struct hash<std::basic_string<C> > : private hash<const C*> {
   size_t operator()(const std::basic_string<C> & s) const {
@@ -471,7 +482,7 @@ struct hash<std::basic_string<C> > : private hash<const C*> {
   }
 };
 
-} // namespace __gnu_cxx
+}
 #endif
 
 // Hook into boost's type traits