With the following macro:
#define ASSERT_IF_TEMP(expr) static_assert(?, "Is temporary!");
What should I put for question mark?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First we should clarify: What do you mean by “temporary”?
Many people mean different things when they say temporary. Technically,
int()is not a temporary, but most people will include them into their own meaning of that term. Technically, givenstd::string s;, thenmove(s)isn’t a temporary either, but you may want to treat it as one with your macro.The first kind of “temporaries” I mentioned above are really “prvalue expressions”. Those are the
std::string("foo")orint()kind of things, but not themove(s)and also (for sure) not theskind of things. Thedecltypeoperator yields a non-reference type for the first kind of “temporaries” I talked about above. For the second kind,move(s), which are xvalues, it will yield an rvalue reference. And for the “non-temporaries”, i.e thescases, it will yield an lvalue reference.So to summarize, I will define three precise macros, and you can choose from them