builder.h 877 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <util/stream/str.h>
  3. #include <utility>
  4. #include <util/generic/string.h>
  5. namespace NPrivateStringBuilder {
  6. class TStringBuilder: public TString {
  7. public:
  8. inline TStringBuilder()
  9. : Out(*this)
  10. {
  11. }
  12. TStringBuilder(TStringBuilder&& rhs) noexcept
  13. : TString(std::move(rhs))
  14. , Out(*this)
  15. {
  16. }
  17. TStringOutput Out;
  18. };
  19. template <class T>
  20. static inline TStringBuilder& operator<<(TStringBuilder& builder Y_LIFETIME_BOUND, const T& t) {
  21. builder.Out << t;
  22. return builder;
  23. }
  24. template <class T>
  25. static inline TStringBuilder&& operator<<(TStringBuilder&& builder Y_LIFETIME_BOUND, const T& t) {
  26. builder.Out << t;
  27. return std::move(builder);
  28. }
  29. }
  30. using TStringBuilder = NPrivateStringBuilder::TStringBuilder;