/* * Copyright (C) 2015 ScyllaDB */ /* * This file is part of Scylla. * * Scylla is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Scylla is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Scylla. If not, see . */ #pragma once #include "core/sstring.hh" #include #include #include #include template static inline sstring join(sstring delimiter, const PrintableRange& items) { return join(delimiter, items.begin(), items.end()); } 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(); } 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::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; } namespace experimental { template std::ostream& operator<<(std::ostream& os, const std::experimental::optional& opt) { if (opt) { os << "{" << *opt << "}"; } else { os << "{}"; } return os; } } }