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

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...