How to extract the source filename without path and suffix at compile time?

1. gcc builtin function can get the file name of a full path at compile time. #define __FILENAME__ (__builtin_strrchr(__FILE__, “https://stackoverflow.com/”) ? __builtin_strrchr(__FILE__, “https://stackoverflow.com/”) + 1 : __FILE__) or #define __FILENAME__ (strrchr(__FILE__, “https://stackoverflow.com/”) ? strrchr(__FILE__, “https://stackoverflow.com/”) + 1 : __FILE__) 2. c++11 constexpr also can do this at compile time. c++11 constexpr function can only use … Read more

Do rvalue references allow dangling references?

Do rvalue references allow dangling references? If you meant “Is it possible to create dangling rvalue references” then the answer is yes. Your example, however, string middle_name () { return “Jaan”; } int main() { string&& nodanger = middle_name(); // OK. // The life-time of the temporary is extended // to the life-time of the … Read more

C++ static constexpr field with incomplete type

Unfortunately, you simply cannot do this! Some static constexpr members may be initialised inline: [C++11 9.4.2/3]: [..] A static data member of literal type can be declared in the class definition with the constexpr specifier; if so, its declaration shall specify a brace-or-equal-initializer in which every initializer-clause that is an assignment-expression is a constant expression. … Read more

Rule of thumb for when passing by value is faster than passing by const reference?

If you have reason to suspect there is a worthwhile performance gain to be had, cut it out with the rules of thumb and measure. The purpose of the advise you quote is that you don’t copy great amounts of data for no reason, but don’t jeopardize optimizations by making everything a reference either. If … Read more

C++11 lambda in decltype

You cannot use a lambda expression except by actually creating that object- that makes it impossible to pass to type deduction like decltype. Ironically, of course, the lambda return rules make it so that you CAN return lambdas from lambdas, as there are some situations in which the return type doesn’t have to be specified. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)