MCPcopy Create free account
hub / github.com/fmtlib/fmt / out

Function out

include/fmt/base.h:1923–1957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1921// A buffer that writes to an output iterator when flushed.
1922template <typename OutputIt, typename T, typename Traits = buffer_traits>
1923class iterator_buffer : public Traits, public buffer<T> {
1924 private:
1925 OutputIt out_;
1926 enum { buffer_size = 256 };
1927 T data_[buffer_size];
1928
1929 static FMT_CONSTEXPR void grow(buffer<T>& buf, size_t) {
1930 if (buf.size() == buffer_size) static_cast<iterator_buffer&>(buf).flush();
1931 }
1932
1933 void flush() {
1934 auto size = this->size();
1935 this->clear();
1936 const T* begin = data_;
1937 const T* end = begin + this->limit(size);
1938 out_ = copy<T>(begin, end, out_);
1939 }
1940
1941 public:
1942 explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
1943 : Traits(n), buffer<T>(grow, data_, 0, buffer_size), out_(out) {}
1944 iterator_buffer(iterator_buffer&& other) noexcept
1945 : Traits(other),
1946 buffer<T>(grow, data_, 0, buffer_size),
1947 out_(other.out_) {}
1948 ~iterator_buffer() {
1949 // Don't crash if flush fails during unwinding.
1950 FMT_TRY { flush(); }
1951 FMT_CATCH(...) {}
1952 }
1953
1954 auto out() -> OutputIt {
1955 flush();
1956 return out_;
1957 }
1958 auto count() const -> size_t { return Traits::count() + this->size(); }
1959};
1960

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected