diff --git a/arangod/Agency/AgencyComm.cpp b/arangod/Agency/AgencyComm.cpp index e4c6ba366b..2fedaa1437 100644 --- a/arangod/Agency/AgencyComm.cpp +++ b/arangod/Agency/AgencyComm.cpp @@ -572,14 +572,6 @@ void AgencyCommManager::failedNonLocking( } -template -inline std::ostream& operator<<(std::ostream& o, std::deque const& d) { - for (const auto& i : d) { - o << i << " "; - } - return o; -} - std::string AgencyCommManager::redirect( std::unique_ptr connection, std::string const& endpoint, std::string const& location, diff --git a/arangod/Agency/State.cpp b/arangod/Agency/State.cpp index 50d824a277..4a5bff76ab 100644 --- a/arangod/Agency/State.cpp +++ b/arangod/Agency/State.cpp @@ -478,14 +478,6 @@ bool State::createCollection(std::string const& name) { return true; } -template -std::ostream& operator<<(std::ostream& o, std::deque const& d) { - for (auto const& i : d) { - o << i; - } - return o; -} - /// Load collections bool State::loadCollections(TRI_vocbase_t* vocbase, QueryRegistry* queryRegistry, bool waitForSync) { diff --git a/lib/Basics/debugging.h b/lib/Basics/debugging.h index 420ad37b3f..f3d45c7110 100644 --- a/lib/Basics/debugging.h +++ b/lib/Basics/debugging.h @@ -114,4 +114,121 @@ void TRI_ShutdownDebugging(); void TRI_FlushDebugging(); void TRI_FlushDebugging(char const* file, int line, char const* message); +//////////////////////////////////////////////////////////////////////////////// +/// @brief dump vector contents to an ostream +//////////////////////////////////////////////////////////////////////////////// + +template +std::ostream& operator<<(std::ostream& stream, std::vector const& data) { + bool first = true; + + stream << "["; + for (auto const& it : data) { + if (first) { + stream << " "; + first = false; + } else { + stream << ", "; + } + stream << it; + } + stream << " ]"; + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief dump deque contents to an ostream +//////////////////////////////////////////////////////////////////////////////// + +template +std::ostream& operator<<(std::ostream& stream, std::deque const& data) { + bool first = true; + + stream << "["; + for (auto const& it : data) { + if (first) { + stream << " "; + first = false; + } else { + stream << ", "; + } + stream << it; + } + stream << " ]"; + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief dump unordered_set contents to an ostream +//////////////////////////////////////////////////////////////////////////////// + +template +std::ostream& operator<<(std::ostream& stream, + std::unordered_set const& data) { + bool first = true; + + stream << "{"; + for (auto const& it : data) { + if (first) { + stream << " "; + first = false; + } else { + stream << ", "; + } + stream << it; + } + stream << " }"; + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief dump unordered_map contents to an ostream +//////////////////////////////////////////////////////////////////////////////// + +template +std::ostream& operator<<(std::ostream& stream, + std::unordered_map const& data) { + bool first = true; + + stream << "{"; + for (auto const& it : data) { + if (first) { + stream << " "; + first = false; + } else { + stream << ", "; + } + stream << it.first << ": " << it.second; + } + stream << " }"; + + return stream; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief dump unordered_map contents to an ostream +//////////////////////////////////////////////////////////////////////////////// + +template +std::ostream& operator<<(std::ostream& stream, std::map const& data) { + bool first = true; + + stream << "{"; + for (auto const& it : data) { + if (first) { + stream << " "; + first = false; + } else { + stream << ", "; + } + stream << it.first << ": " << it.second; + } + stream << " }"; + + return stream; +} + #endif diff --git a/lib/Logger/LoggerStream.h b/lib/Logger/LoggerStream.h index 7dab9306c8..2c263ef405 100644 --- a/lib/Logger/LoggerStream.h +++ b/lib/Logger/LoggerStream.h @@ -88,52 +88,6 @@ class LoggerStream { return *this; } - template - LoggerStream& operator<<(std::vector const& obj) { - _out << '['; - size_t i = 0; - size_t const n = obj.size(); - for (auto const& it : obj) { - _out << it; - if (++i < n) { - _out << ", "; - } - } - _out << ']'; - return *this; - } - - template - LoggerStream& operator<<(std::unordered_set const& obj) { - _out << '{'; - size_t i = 0; - size_t const n = obj.size(); - for (auto const& it : obj) { - _out << it; - if (++i < n) { - _out << ", "; - } - } - _out << '}'; - return *this; - } - - template - LoggerStream& operator<<(std::unordered_map const& obj) { - _out << '{'; - size_t i = 0; - size_t n = obj.size(); - for (auto const& it : obj) { - _out << it; - if (++i < n) { - _out << ", "; - } - _out << it.first << " => " << it.second; - } - _out << '}'; - return *this; - } - private: std::stringstream _out; size_t _topicId;