format_arg-inl.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef FORMAT_ARG_INL_H_
  2. #error "Direct inclusion of this file is not allowed, include format_arg.h"
  3. // For the sake of sane code completion.
  4. #include "format_arg.h"
  5. #endif
  6. namespace NYT {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. namespace NDetail {
  9. template <class T>
  10. constexpr std::string_view QualidName()
  11. {
  12. constexpr size_t openBracketOffset = 5;
  13. constexpr size_t closeBracketOffset = 1;
  14. constexpr std::string_view func = __PRETTY_FUNCTION__;
  15. constexpr auto left = std::find(std::begin(func), std::end(func), '[') + openBracketOffset;
  16. return std::string_view(left, std::prev(std::end(func), closeBracketOffset));
  17. }
  18. template <class T>
  19. constexpr bool IsNYTName()
  20. {
  21. constexpr auto qualidName = QualidName<T>();
  22. return qualidName.find("NYT::") == 0;
  23. }
  24. template <class T>
  25. constexpr bool IsStdName()
  26. {
  27. constexpr auto qualidName = QualidName<T>();
  28. return qualidName.find("std::") == 0;
  29. }
  30. } // namespace NDetail
  31. ////////////////////////////////////////////////////////////////////////////////
  32. template <bool Hot, size_t N, std::array<char, N> List, class TFrom>
  33. consteval auto TFormatArgBase::ExtendConversion()
  34. {
  35. static_assert(std::same_as<TFrom, TFormatArgBase> || CFormattable<TFrom>);
  36. return AppendArrays<Hot, N, List, &TFormatArg<TFrom>::ConversionSpecifiers>();
  37. }
  38. template <bool Hot, size_t N, std::array<char, N> List, class TFrom>
  39. consteval auto TFormatArgBase::ExtendFlags()
  40. {
  41. static_assert(std::same_as<TFrom, TFormatArgBase> || CFormattable<TFrom>);
  42. return AppendArrays<Hot, N, List, &TFormatArg<TFrom>::FlagSpecifiers>();
  43. }
  44. template <bool Hot, size_t N, std::array<char, N> List, auto* From>
  45. consteval auto TFormatArgBase::AppendArrays()
  46. {
  47. auto& from = *From;
  48. return [] <size_t... I, size_t... J> (
  49. std::index_sequence<I...>,
  50. std::index_sequence<J...>) {
  51. if constexpr (Hot) {
  52. return std::array{List[J]..., from[I]...};
  53. } else {
  54. return std::array{from[I]..., List[J]...};
  55. }
  56. } (
  57. std::make_index_sequence<std::size(from)>(),
  58. std::make_index_sequence<N>());
  59. }
  60. ////////////////////////////////////////////////////////////////////////////////
  61. } // namespace NYT