@@ -86,6 +86,50 @@ typedef struct _GUID GUID;
86
86
// release binaries, or to reduce binary size. Defining WINRT_NO_SOURCE_LOCATION will prevent this feature from activating.
87
87
#if defined(__cpp_lib_source_location) && !defined(WINRT_NO_SOURCE_LOCATION)
88
88
89
+ namespace winrt ::impl
90
+ {
91
+ // This struct is intended to be highly similar to std::source_location. The key difference is
92
+ // that function_name is NOT included. Function names do not fold to identical strings and can
93
+ // have heavy binary size overhead when templates cause many permutations to exist.
94
+ struct slim_source_location
95
+ {
96
+ [[nodiscard]] static consteval slim_source_location current (
97
+ const std::uint_least32_t line = __builtin_LINE(),
98
+ const char* const file = __builtin_FILE()) noexcept
99
+ {
100
+ return slim_source_location{ line, file };
101
+ }
102
+
103
+ [[nodiscard]] constexpr slim_source_location () noexcept = default;
104
+
105
+ [[nodiscard]] constexpr slim_source_location (const std::uint_least32_t line,
106
+ const char * const file) noexcept :
107
+ m_line(line),
108
+ m_file(file)
109
+ {}
110
+
111
+ [[nodiscard]] constexpr std::uint_least32_t line () const noexcept
112
+ {
113
+ return m_line;
114
+ }
115
+
116
+ [[nodiscard]] constexpr const char * file_name () const noexcept
117
+ {
118
+ return m_file;
119
+ }
120
+
121
+ constexpr const char * function_name () const noexcept
122
+ {
123
+ // This is intentionally not included. See comment above.
124
+ return nullptr ;
125
+ }
126
+
127
+ private:
128
+ const std::uint_least32_t m_line{};
129
+ const char * const m_file{};
130
+ };
131
+ }
132
+
89
133
// std::source_location includes function_name which can be helpful but creates a lot of binary size impact. Many consumers
90
134
// have defined WINRT_NO_SOURCE_LOCATION to prevent this impact, losing the value of source_location. We have defined a
91
135
// slim_source_location struct that is equivalent but excludes function_name. This should have the vast majority of the
@@ -122,8 +166,6 @@ typedef struct _GUID GUID;
122
166
123
167
#endif // _DEBUG
124
168
125
-
126
- #endif
127
169
#else
128
170
#define WINRT_IMPL_SOURCE_LOCATION_ARGS_NO_DEFAULT
129
171
#define WINRT_IMPL_SOURCE_LOCATION_ARGS
@@ -134,5 +176,5 @@ typedef struct _GUID GUID;
134
176
135
177
#ifdef _MSC_VER
136
178
#pragma detect_mismatch("WINRT_SOURCE_LOCATION", "false")
137
- #endif
138
- #endif
179
+ #endif // _MSC_VER
180
+ #endif // defined(__cpp_lib_source_location) && !defined(WINRT_NO_SOURCE_LOCATION)
0 commit comments