convert_to_cpo.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <library/cpp/yt/misc/tag_invoke_cpo.h>
  3. #include <util/generic/strbuf.h>
  4. namespace NYT {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. // NB(arkady-e1ppa): This file intentionally is unaware of possible "yson-implementations"
  7. // e.g. INode and TYsonString(Buf). This is done for two reasons:
  8. // 1) We can't have dep on INodePtr here anyway.
  9. // 2) We would like to eventually remove dep on yson of this module.
  10. ////////////////////////////////////////////////////////////////////////////////
  11. // NB(arkady-e1ppa): We intentionally generate a separate namespace
  12. // where ConvertToImpl functions would reside
  13. // without polluting general-use namespaces.
  14. namespace NConvertToImpl {
  15. template <class T>
  16. struct TFn : public NYT::TTagInvokeCpoBase<TFn<T>>
  17. { };
  18. } // NConvertToImpl
  19. ////////////////////////////////////////////////////////////////////////////////
  20. template <class T>
  21. inline constexpr NConvertToImpl::TFn<T> ConvertTo = {};
  22. ////////////////////////////////////////////////////////////////////////////////
  23. template <class TTo, class TFrom>
  24. concept CConvertToWorks = requires (const TFrom& from) {
  25. { NYT::ConvertTo<TTo>(from) } -> std::same_as<TTo>;
  26. };
  27. ////////////////////////////////////////////////////////////////////////////////
  28. } // namespace NYT