c++ - Boilerplate function name -
on projects have been on, have boilerplate code creating local variable function name. fastest/best way? or, there faster/better way it? these functions called frequently, , it's performance-critical project. so, what's best way initialize our function names?
some have seen:
/*1*/ const static std::string functionname("function1"); /*2*/ const static std::string functionname( __pretty_function__ ); /*3*/ const std::string functionname("function1"); /*4*/ const char functionname [] = "function1";
edit: figured obvious, reason use such declaration can use functionname variable print out debugging information in function. maybe reason it's not obvious because aren't implementing well. love hear other ways implement this.
c++11 8.4.1/8:
the function-local predefined variable
__func__
defined if definition of formstatic const char __func__[] = "function-name";
had been provided, function-name implementation-defined string. unspecified whether such variable has address distinct of other object in program.
[ example:
struct s { s() : s(__func__) { } // ok const char *s; }; void f(const char * s = __func__); // error: __func__ undeclared
—end example ]
Comments
Post a Comment