/*
- * 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"
*/
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().
*/
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) {
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 {
}
};
-} // namespace __gnu_cxx
+}
#endif
// Hook into boost's type traits