1 // Copyright 2021 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef QUICHE_COMMON_PRINT_ELEMENTS_H_ 6 #define QUICHE_COMMON_PRINT_ELEMENTS_H_ 7 8 #include <ostream> 9 #include <sstream> 10 #include <string> 11 12 #include "quiche/common/platform/api/quiche_export.h" 13 14 namespace quiche { 15 16 // Print elements of any iterable container that has cbegin() and cend() methods 17 // and the elements have operator<<(ostream) override. 18 template <typename T> PrintElements(const T & container)19QUICHE_EXPORT inline std::string PrintElements(const T& container) { 20 std::stringstream debug_string; 21 debug_string << "{"; 22 auto it = container.cbegin(); 23 if (it != container.cend()) { 24 debug_string << *it; 25 ++it; 26 while (it != container.cend()) { 27 debug_string << ", " << *it; 28 ++it; 29 } 30 } 31 debug_string << "}"; 32 return debug_string.str(); 33 } 34 35 } // namespace quiche 36 37 #endif // QUICHE_COMMON_PRINT_ELEMENTS_H_ 38