Home arrow C++ arrow Page 2 - Temporary Variables: Runtime rvalue Detection

Temporary Variables: Runtime rvalue Detection

In this final article in the series covering temporary variables, Jun Nakamura explains how you can test whether a variable is temporary or not, by using the ternary conditional operator.

Author Info:
By: J. Nakamura
Rating: 4 stars4 stars4 stars4 stars4 stars / 6
October 17, 2005
  1. · Temporary Variables: Runtime rvalue Detection
  2. · The Ternary Conditional Operator
  3. · The RVALUE_TEST macro
  4. · Determining Type

print this article

Temporary Variables: Runtime rvalue Detection - The Ternary Conditional Operator
(Page 2 of 4 )

conditional expression:                                                                                                      


                logical-or-expression ? expression : assignment-expression

[the C++ Standard]

This operator allows you to compact an "if-then-else" statement into one single statement. Instead of writing:

if ( value==true ) { desc=”true”; } else { desc=”false”; }

You can use the ternary operator:

desc = value ? “true” : “false”;

This operator takes an expression to evaluate, then an expression to evaluate whether the condition is true and an expression to evaluate whether the condition is false. The first expression is implicitly converted to bool and if it is true, the result of the conditional expression is the second expression, otherwise that of the third expression.

blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials