aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/builder.h
blob: 9da648246407cb13644c2168272ed0ecf932dad1 (plain) (blame)
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
38
39
#pragma once

#include <util/stream/str.h>
#include <utility>
#include <util/generic/string.h>

namespace NPrivateStringBuilder {
    class TStringBuilder: public TString {
    public:
        inline TStringBuilder()
            : Out(*this)
        {
        }

        TStringBuilder(TStringBuilder&& rhs) noexcept
            : TString(std::move(rhs))
            , Out(*this)
        {
        }

        TStringOutput Out;
    };

    template <class T>
    static inline TStringBuilder& operator<<(TStringBuilder& builder Y_LIFETIME_BOUND, const T& t) {
        builder.Out << t;

        return builder;
    }

    template <class T>
    static inline TStringBuilder&& operator<<(TStringBuilder&& builder Y_LIFETIME_BOUND, const T& t) {
        builder.Out << t;

        return std::move(builder);
    }
} // namespace NPrivateStringBuilder

using TStringBuilder = NPrivateStringBuilder::TStringBuilder;