sfinae

Check if a class has a member function of a given signature

寵の児 提交于 2019-11-25 22:08:07
问题 I\'m asking for a template trick to detect if a class has a specific member function of a given signature. The problem is similar to the one cited here http://www.gotw.ca/gotw/071.htm but not the same: in the item of Sutter\'s book he answered to the question that a class C MUST PROVIDE a member function with a particular signature, else the program won\'t compile. In my problem I need to do something if a class has that function, else do \"something else\". A similar problem was faced by

How can I add reflection to a C++ application?

烈酒焚心 提交于 2019-11-25 21:48:01
问题 I\'d like to be able to introspect a C++ class for its name, contents (i.e. members and their types) etc. I\'m talking native C++ here, not managed C++, which has reflection. I realise C++ supplies some limited information using RTTI. Which additional libraries (or other techniques) could supply this information? 回答1: What you need to do is have the preprocessor generate reflection data about the fields. This data can be stored as nested classes. First, to make it easier and cleaner to write

Why do constant expressions have an exclusion for undefined behavior?

て烟熏妆下的殇ゞ 提交于 2019-11-25 19:36:52
I was researching what is allowed in a core constant expression* , which is covered in section 5.19 Constant expressions paragraph 2 of the draft C++ standard which says: A conditional-expression is a core constant expression unless it involves one of the following as a potentially evaluated subexpression (3.2), but subexpressions of logical AND (5.14), logical OR (5.15), and conditional (5.16) operations that are not evaluated are not considered [ Note: An overloaded operator invokes a function.—end note ]: and lists out the exclusions in the bullets that follows and includes ( emphasis mine