Questions tagged [std-source-location]

A C++ standard library construct for accessing the location of a line of source code, at compile time.

C++20 introduced a class which enables compile-time access and manipulation of the location of lines of source code. With earlier standard versions of the language, one had to avail one's self of the __FILE__ and __LINE__ macros for a similar functionality.

See a longer description with examples on cppreference.com.

22 questions
0
votes
0 answers

C++ correct usage of std::source_location

I'm trying to use std::source_location in combination with a logging mechanism. However it turns out that std::source_location points to the wrong location. For reference the compiler explorer link https://godbolt.org/z/Wx3har1zG The problem was…
JHeni
  • 455
  • 3
  • 12
0
votes
0 answers

C++20 source_location template non-type parameter

I was trying to figure out ways to use std::source_location::current(), when I stumbled upon this particular answer for a thread. I tried running the code on godbolt with x86-64 gcc 13.1 and -O3 -std=c++20 -Wall -Wextra -Wpedantic, but it doesn't…
spaL
  • 604
  • 7
  • 21
0
votes
2 answers

How can I pass CMake's CMAKE_SOURCE_DIR to C++ source files?

In my C++ program I use std::source_location for log output. The printed path is currently absolute. The project is built with CMake. I want to shorten the std::source_location path according to the CMake variable CMAKE_SOURCE_DIR. How can I access…
Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
0
votes
1 answer

Replacing __LINE__ and __FUNCSIG__ with the new std::source_location in a macro

C++20 added std::source_location as a replacement for the debugging macros __LINE__, __FILE__, etc. This is great. I have a macro that builds up a variable declaration in order to log and profile a block of code using said macros: #define…
Casey
  • 10,297
  • 11
  • 59
  • 88
0
votes
1 answer

operator[] caller's site source location current workaround

sadly, the current source location can't be used directly in the parameter list of operator[], as this operator has to have only one argument. However, is there a workaround so I can get the callers source line? Consider this code for…
0
votes
1 answer

How to disable copy elision for constructors with std::source_location?

I am trying to add instrumentation to a widely used template class in my product. I am currently on VS 2019 (16.10.4) with /std:c++17. The new feature of std::source_location is a great addition for the kind of task I am interested in solving. …
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
0
votes
0 answers

Why are std::source_location's getters not marked as [[nodiscard]]?

According to: https://en.cppreference.com/w/cpp/utility/source_location the getters aren't marked as [[nodiscard]]. constexpr uint_least32_t line() const noexcept; constexpr uint_least32_t column() const noexcept; constexpr const char*…
1
2