Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

c++ - Capture __LINE__ and __FILE__ without #define

Trying to determine a "modern" implementation for the following C-style code:

#define logError(...) log(__FILE__, __LINE__, __VA_ARGS__)

Is is possible to capture this using variadic templates or something similar that does not rely on a #define ?

Desired use case:

logError( "Oh no! An error occurred!" );

Where __FILE__, and __LINE__ are captured under the hood, but reflect the file name and line number of where logError was called from.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Macros are indeed your only choice, at least until std::source_location makes it into the standard and fulfills your wish.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...