All Questions
Tagged with ternary-operator or conditional-operator
3,857 questions
3 votes
1 answer
144 views
Conditional operator with a throwing branch in Visual C++ 2026
My program changed its behavior after updating Visual Studio to the latest version (2026). Simplifying it, I got the following minimal example, which contains a ternary operator with a throw in ...
1 vote
3 answers
110 views
How to add multiple children based on single ternary operator in Flutter Row
How to add multiple children based on single ternary operator in Flutter Row? Row( children: [ Widget1(), n.type != null ? { Icon( Icons.access_time, size: 14, ...
0 votes
1 answer
46 views
How to model a many-to-many relationship in DynamoDB with composite keys and enforce unique (id, ruleId) pairs?
I have a DynamoDB table defined as follows: Partition key: id (string) Sort key: ruleId (string) Example item: { "id": "123", "ruleId": "abc" } What I want is ...
5 votes
0 answers
176 views
When is the ternary operator suitable for copy elision? [duplicate]
According to this article by Raymond Chen, ternary expression is not a copy elision candidate. The problem with the ternary is that the ternary expression is not a copy elision candidate. The rule ...
14 votes
1 answer
815 views
Copy constructor is called with result of rvalue conditional operator
According to cppreference, value category of conditional operator in C++ depends on categories of the operands, namely: if both operands are lvalues, then conditional operator is also lvalue, ...
1 vote
1 answer
223 views
Why ternary operator cannot be used for this statement? [duplicate]
This code gives me compiler error: "expected an expression". std::array< std::string, 3 > candidates = useOutname ? { "%O.log", "%O_.log", "_%O.log" } : { ...
0 votes
1 answer
67 views
Ternary operator initialization producing incorrect static type [duplicate]
I'm perplexed by the vscode hover hints and tsc (v5.8.3) messages I am seeing as I initialize a variable with a ternary expression that might return my trivial custom class. They seem to incorrectly ...
5 votes
2 answers
193 views
How does the `(…) and (…) or (…)` idiom mimic a ternary operator in Lua?
This statement mimics a ternary operator in the Lua programing language: local result = condition and true_value or false_value But how does it work? Why does it give true_value if the condition is ...
4 votes
1 answer
116 views
Error using ternary operator and method overloading of wrapper class in Java 8 only
I am using Java 8 and facing some weird error. The compiler gives the following error: error: reference to [method] is ambiguous Here's my code StringBuilder sb = new StringBuilder(); Stack<...
0 votes
1 answer
287 views
nunjucks ternary if expression
I'm using nunjucks as a templating engine in my application and can't seem to get the block to display at all when I apply more than two conditions e.g. {{ "true" if foo else "false&...
0 votes
1 answer
92 views
pandas dataframe select rows with ternary operator
My requirement is simple, I need to select the rows from a Pandas DataFrame when one of two couple columns are populated or both. The attributes contain integer foreign keys. This works: ...
1 vote
1 answer
87 views
How do conditional expressions group from right to left?
I checked python operator precedence (This one grammar is more detailed and more appropriate for the actual Python implementation) Operators in the same box group left to right (except for ...
1 vote
0 answers
107 views
conditional operator with derived and base classes with conversion operator to built-in types issue, compiler bug?
This example: struct X {}; struct Y : X {}; using CY = const Y; true ? X() : CY(); // error Which is explained in this answer, could be changed like this: struct X { operator int() { return 0; } }; ...
3 votes
0 answers
72 views
conditional operator: inconsistency between implicit conversion sequence used for different compilers
This is a follow-up of this question: conditional operator expression with base and const derived class doesn't compile, why?. The core is cond ? [cv] T1() : [cv] T2() where, for instance T2 ...
0 votes
2 answers
744 views
What does perl substitution operator return when applied to a string?
I can't understand what does the perl substitution return after applied. I have the following snippet my $w = "-foo"; my $v = $w =~ s/-//?0:1; print "---- $v\n"; If $w is -foo,...