File: tostr.hpp

package info (click to toggle)
gemmi 0.5.7%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,344 kB
  • sloc: cpp: 48,972; python: 4,352; ansic: 3,428; sh: 302; makefile: 69; f90: 42; javascript: 12
file content (32 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (2)
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
// Copyright 2019 Global Phasing Ltd.
//
// gemmi::tostr() - converts a list of arguments to string (uses ostringstream).
// It was replaced with cat() and currently it's used only in Python bindings.

#ifndef GEMMI_TOSTR_HPP_
#define GEMMI_TOSTR_HPP_

#include <sstream>
#include <string>

namespace gemmi {

namespace impl {
inline void add_to_stream(std::ostringstream&) {}

template<typename T, typename... Args>
void add_to_stream(std::ostringstream& os, T&& value, Args&&... args) {
  os << std::forward<T>(value);
  add_to_stream(os, std::forward<Args>(args)...);
}
} // namespace impl

template<typename T, typename... Args>
std::string tostr(T&& value, Args&&... args) {
  std::ostringstream os;
  impl::add_to_stream(os, std::forward<T>(value), std::forward<Args>(args)...);
  return os.str();
}

} // namespace gemmi
#endif