summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quiche/common/print_elements.h
blob: 627b4c9cffeac08807a6af604dbb854a5875e30f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef QUICHE_COMMON_PRINT_ELEMENTS_H_
#define QUICHE_COMMON_PRINT_ELEMENTS_H_

#include <ostream>
#include <sstream>
#include <string>

#include "quiche/common/platform/api/quiche_export.h"

namespace quiche {

// Print elements of any iterable container that has cbegin() and cend() methods
// and the elements have operator<<(ostream) override.
template <typename T>
QUICHE_EXPORT_PRIVATE inline std::string PrintElements(const T& container) {
  std::stringstream debug_string;
  debug_string << "{";
  auto it = container.cbegin();
  if (it != container.cend()) {
    debug_string << *it;
    ++it;
    while (it != container.cend()) {
      debug_string << ", " << *it;
      ++it;
    }
  }
  debug_string << "}";
  return debug_string.str();
}

}  // namespace quiche

#endif  // QUICHE_COMMON_PRINT_ELEMENTS_H_