should std::common_type use std::decay?

should std::common_type use std::decay? Yes, see Library Working Group Defect #2141. Short version (long version, see link above): declval<A>() returns a A&& common_type is specified via declval, n3337: template <class T, class U> struct common_type<T, U> { typedef decltype(true ? declval<T>() : declval<U>()) type; }; common_type<int, int>::type therefore yields int&&, which is unexpected proposed resolution … Read more

Kotlin Ternary Conditional Operator

In Kotlin, if statements are expressions. So the following code is equivalent: if (a) b else c The distinction between expression and statement is important here. In Java/C#/JavaScript, if forms a statement, meaning that it does not resolve to a value. More concretely, you can’t assign it to a variable. // Valid Kotlin, but invalid … Read more

Why doesn’t the conditional operator correctly allow the use of “null” for assignment to nullable types? [duplicate]

This doesn’t work because the compiler will not insert an implicit conversion on both sides at once, and null requires an implicit conversion to become a nullable type. Instead, you can write task.ActualEndDate = TextBoxActualEndDate.Text != “” ? DateTime.Parse(TextBoxActualEndDate.Text) : new DateTime?(); This only requires one implicit conversion (DateTime to DateTime?). Alternatively, you can cast … Read more

“or” conditional in Python troubles [duplicate]

Boolean expressions in most programming languages don’t follow the same grammar rules as English. You have to do separate comparisons with each string, and connect them with or: if x == “monkey” or x == “monkeys”: print “You’re right, they are awesome!!” else: print “I’m sorry, you’re incorrect.”, x[0].upper() + x[1:], “is not the right … Read more

Is the conditional operator slow?

Very odd, perhaps .NET optimization is backfireing in your case: The author disassembled several versions of ternary expressions and found that they are identical to if-statements, with one small difference. The ternary statement sometimes produces code that tests the opposite condition that you would expect, as in it tests that the subexpression is false instead … Read more