/* * Copyright (C) 2015-present ScyllaDB */ /* * SPDX-License-Identifier: AGPL-3.0-or-later */ #pragma once #include #include #include #include #include #include #include #include #include "seastarx.hh" #include "utils/chunked_vector.hh" template static inline sstring join(sstring delimiter, Iterator begin, Iterator end) { std::ostringstream oss; while (begin != end) { oss << *begin; ++begin; if (begin != end) { oss << delimiter; } } return oss.str(); } template static inline sstring join(sstring delimiter, const PrintableRange& items) { return join(delimiter, items.begin(), items.end()); } template struct print_with_comma { const Printable& v; }; template std::ostream& operator<<(std::ostream& os, const print_with_comma& x) { os << x.v; if (NeedsComma) { os << ", "; } return os; } namespace std { template static inline sstring to_string(const std::vector& items) { return "[" + join(", ", items) + "]"; } template static inline sstring to_string(const std::set& items) { return "{" + join(", ", items) + "}"; } template static inline sstring to_string(const std::unordered_set& items) { return "{" + join(", ", items) + "}"; } template static inline sstring to_string(std::initializer_list items) { return "[" + join(", ", std::begin(items), std::end(items)) + "]"; } template std::ostream& operator<<(std::ostream& os, const std::pair& p) { os << "{" << p.first << ", " << p.second << "}"; return os; } template std::ostream& print_tuple(std::ostream& os, const std::tuple& p, std::index_sequence) { return ((os << "{" ) << ... << print_with_comma{std::get(p)}) << "}"; } template std::ostream& operator<<(std::ostream& os, const std::tuple& p) { return print_tuple(os, p, std::make_index_sequence()); } template std::ostream& operator<<(std::ostream& os, const std::unordered_set& items) { os << "{" << join(", ", items) << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::set& items) { os << "{" << join(", ", items) << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::array& items) { os << "{" << join(", ", items) << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::unordered_map& items) { os << "{" << join(", ", items) << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::map& items) { os << "{" << join(", ", items) << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const utils::chunked_vector& items) { os << "[" << join(", ", items) << "]"; return os; } template std::ostream& operator<<(std::ostream& os, const std::list& items) { os << "[" << join(", ", items) << "]"; return os; } template std::ostream& operator<<(std::ostream& os, const std::optional& opt) { if (opt) { os << "{" << *opt << "}"; } else { os << "{}"; } return os; } static inline std::ostream& operator<<(std::ostream& os, const std::strong_ordering& order) { if (order > 0) { os << "gt"; } else if (order < 0) { os << "lt"; } else { os << "eq"; } return os; } }