#pragma once #include #ifdef __cpp_lib_source_location #include #endif // __cpp_lib_source_location namespace NYT { //////////////////////////////////////////////////////////////////////////////// template struct TSourceLocationLite { char FileName[N + 1]; i64 Line; }; template consteval TSourceLocationLite MakeSourceLocationLite(const char* fileName, i64 line); //////////////////////////////////////////////////////////////////////////////// class TSourceLocation { public: TSourceLocation() = default; TSourceLocation(const char* fileName, int line); #ifdef __cpp_lib_source_location explicit TSourceLocation(const std::source_location& location); #endif // __cpp_lib_source_location template static TSourceLocation FromLite(); const char* GetFileName() const; int GetLine() const; bool IsValid() const; bool operator<(const TSourceLocation& other) const; bool operator==(const TSourceLocation& other) const; private: const char* FileName_ = nullptr; int Line_ = -1; }; #ifdef __cpp_lib_source_location #define YT_CURRENT_SOURCE_LOCATION_LITE \ ::NYT::MakeSourceLocationLite::length(std::source_location::current().file_name())>( \ std::source_location::current().file_name(), \ std::source_location::current().line()) #else #define YT_CURRENT_SOURCE_LOCATION_LITE ::NYT::MakeSourceLocationLite::length(__FILE__)>(__FILE__, __LINE__) #endif // __cpp_lib_source_location //! Defines a macro to record the current source location. #ifdef __cpp_lib_source_location #define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(std::source_location::current()) #else #define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(__FILE__, __LINE__) #endif // __cpp_lib_source_location //////////////////////////////////////////////////////////////////////////////// } // namespace NYT #define SOURCE_LOCATION_INL_H_ #include "source_location-inl.h" #undef SOURCE_LOCATION_INL_H_