aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-07-02 08:07:30 +0300
committerbabenko <babenko@yandex-team.com>2024-07-02 08:18:46 +0300
commit318b857015da326b953274ecd06f29565f6f53ae (patch)
tree7867e72618dd673a1b074fcb39c5874073d361c9 /library
parentbc3f0aedccfabb25a5bf14f023401837907a12a7 (diff)
downloadydb-318b857015da326b953274ecd06f29565f6f53ae.tar.gz
YT-18571: Polish TSourceLocation
81b1c42ea62adf4f2a7e2e7ba3601ca9687e29ed
Diffstat (limited to 'library')
-rw-r--r--library/cpp/yt/misc/source_location-inl.h25
-rw-r--r--library/cpp/yt/misc/source_location.cpp7
-rw-r--r--library/cpp/yt/misc/source_location.h33
3 files changed, 38 insertions, 27 deletions
diff --git a/library/cpp/yt/misc/source_location-inl.h b/library/cpp/yt/misc/source_location-inl.h
new file mode 100644
index 0000000000..9948260874
--- /dev/null
+++ b/library/cpp/yt/misc/source_location-inl.h
@@ -0,0 +1,25 @@
+#ifndef SOURCE_LOCATION_INL_H_
+#error "Direct inclusion of this file is not allowed, include source_location.h"
+// For the sake of sane code completion.
+#include "source_location.h"
+#endif
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+inline TSourceLocation::TSourceLocation(const char* fileName, int line)
+ : FileName_(fileName)
+ , Line_(line)
+{ }
+
+#ifdef __cpp_lib_source_location
+inline TSourceLocation::TSourceLocation(const std::source_location& location)
+ : FileName_(location.file_name())
+ , Line_(location.line())
+{ }
+#endif // __cpp_lib_source_location
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace std
diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp
index f3f396ee90..598126f5a7 100644
--- a/library/cpp/yt/misc/source_location.cpp
+++ b/library/cpp/yt/misc/source_location.cpp
@@ -70,13 +70,6 @@ bool TSourceLocation::operator==(const TSourceLocation& other) const
Line_ == other.Line_;
}
-#ifdef __cpp_lib_source_location
-TSourceLocation TSourceLocation::FromStd(const std::source_location& location)
-{
- return TSourceLocation(location.file_name(), location.line());
-}
-#endif // __cpp_lib_source_location
-
void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf /*spec*/)
{
if (location.GetFileName() != nullptr) {
diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h
index 0496a4e496..286527887a 100644
--- a/library/cpp/yt/misc/source_location.h
+++ b/library/cpp/yt/misc/source_location.h
@@ -14,9 +14,7 @@ class TStringBuilderBase;
// TODO(dgolear): Drop when LLVM-14 is eradicated.
#ifdef __cpp_lib_source_location
-
void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/);
-
#endif // __cpp_lib_source_location
////////////////////////////////////////////////////////////////////////////////
@@ -24,15 +22,11 @@ void FormatValue(TStringBuilderBase* builder, const std::source_location& locati
class TSourceLocation
{
public:
- TSourceLocation()
- : FileName_(nullptr)
- , Line_(-1)
- { }
-
- TSourceLocation(const char* fileName, int line)
- : FileName_(fileName)
- , Line_(line)
- { }
+ 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
const char* GetFileName() const;
int GetLine() const;
@@ -41,21 +35,16 @@ public:
bool operator<(const TSourceLocation& other) const;
bool operator==(const TSourceLocation& other) const;
-#ifdef __cpp_lib_source_location
- static TSourceLocation FromStd(const std::source_location& location);
-#endif // __cpp_lib_source_location
-
private:
- const char* FileName_;
- int Line_;
-
+ const char* FileName_ = nullptr;
+ int Line_ = -1;
};
//! Defines a macro to record the current source location.
#ifdef __cpp_lib_source_location
-#define FROM_HERE ::NYT::TSourceLocation::FromStd(std::source_location::current())
+#define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(std::source_location::current())
#else
-#define FROM_HERE ::NYT::TSourceLocation(__FILE__, __LINE__)
+#define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(__FILE__, __LINE__)
#endif // __cpp_lib_source_location
void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf spec);
@@ -63,3 +52,7 @@ void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, T
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
+
+#define SOURCE_LOCATION_INL_H_
+#include "source_location-inl.h"
+#undef SOURCE_LOCATION_INL_H_