ztstrbuf.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. #include <util/generic/string.h>
  4. #include <util/str_stl.h>
  5. /*
  6. * Zero-terminated string view.
  7. *
  8. * Has a c_str() for use with system/cstdlib calls (like TString)
  9. * but can be constructed from a string literal or command-line arg
  10. * without memory allocation (like TStringBuf).
  11. *
  12. * Use it to reference filenames, thread names, string formats etc.
  13. */
  14. class TZtStringBuf: public TStringBuf {
  15. public:
  16. constexpr TZtStringBuf(const char* s Y_LIFETIME_BOUND) noexcept
  17. : TStringBuf(s)
  18. {
  19. }
  20. TZtStringBuf(const TString& s Y_LIFETIME_BOUND) noexcept
  21. : TStringBuf(s)
  22. {
  23. }
  24. TZtStringBuf(const std::string& s Y_LIFETIME_BOUND) noexcept
  25. : TStringBuf(s)
  26. {
  27. }
  28. constexpr TZtStringBuf() noexcept
  29. : TZtStringBuf("")
  30. {
  31. }
  32. TZtStringBuf(const TStringBuf&) = delete;
  33. constexpr const char* c_str() const noexcept {
  34. return data();
  35. }
  36. };
  37. template <>
  38. struct THash<TZtStringBuf> : public THash<TStringBuf> {
  39. };