ztstrbuf.h 804 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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)
  17. : TStringBuf(s)
  18. {
  19. }
  20. TZtStringBuf(const TString& s)
  21. : TStringBuf(s)
  22. {
  23. }
  24. TZtStringBuf()
  25. : TZtStringBuf(TString{})
  26. {
  27. }
  28. const char* c_str() const {
  29. return data();
  30. }
  31. };
  32. template <>
  33. struct THash<TZtStringBuf> : public THash<TStringBuf> {
  34. };