Getting line numbers without macros
C++ 20 includes a new class that will help us get line numbers. In fact, it has a lot more information than just the line number. It includes the name of the file, the function name, and even the column number. However, we only need the line number. Note that at the time of writing this book, the implementation of this new class for my compiler has a bug. The end result is that I have had to put the code back to the way it was before the changes described in this section.
The new class is called source_location
, and once it finally works correctly, we can change all of the existing confirm
functions so that they accept std::source_location
instead of the int for the line number. One example of an existing confirm
function looks like this:
inline void confirm (
bool expected,
bool actual,
int line)
{
if (actual != expected)
...