aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils/ztstrbuf/ztstrbuf.h
blob: fcca39698ba12258ebbaecdaba81757c84b125f2 (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
40
41
42
43
44
45
46
47
48
#pragma once

#include <util/generic/strbuf.h>
#include <util/generic/string.h>
#include <util/str_stl.h>

/*
 * Zero-terminated string view.
 *
 * Has a c_str() for use with system/cstdlib calls (like TString)
 * but can be constructed from a string literal or command-line arg
 * without memory allocation (like TStringBuf).
 *
 * Use it to reference filenames, thread names, string formats etc.
 */

class TZtStringBuf: public TStringBuf {
public:
    constexpr TZtStringBuf(const char* s Y_LIFETIME_BOUND) noexcept
        : TStringBuf(s)
    {
    }

    TZtStringBuf(const TString& s Y_LIFETIME_BOUND) noexcept
        : TStringBuf(s)
    {
    }

    TZtStringBuf(const std::string& s Y_LIFETIME_BOUND) noexcept
        : TStringBuf(s)
    {
    }

    constexpr TZtStringBuf() noexcept
        : TZtStringBuf("")
    {
    }

    TZtStringBuf(const TStringBuf&) = delete;

    constexpr const char* c_str() const noexcept {
        return data();
    }
};

template <>
struct THash<TZtStringBuf> : public THash<TStringBuf> {
};