Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:05:56+00:00 2026-06-17T06:05:56+00:00

Below is one of the specializations of std::common_type . template <class T, class U>

  • 0

Below is one of the specializations of std::common_type.

template <class T, class U>
struct common_type<T, U> {
    typedef decltype(true ? declval<T>() : declval<U>()) type;
};

My notion is that the conditional statement is unnecessary. If it’s checking against true, won’t the expression invariably resolve to declval<T>()? And if so, how does the returned typedef justify the definition…

“Determines the common type among all types T..., that is the type all T... can be implicitly converted to.”

Can someone please explain the conditional statement? Is it accurate that the check against true is superfluous, and that the condition will always resolve to the first operand? And if so, how does the type that is returned satisfy the definition?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:05:58+00:00Added an answer on June 17, 2026 at 6:05 am

    The ternary operator’s type isn’t just the type of the branch the compiler knows it has to take. It is the type which is common to both branches if there is such a type. If there is no such type, the compilation fails. The ternary operator is the only operator with the property that it converts to the common type of the expressions rather than to the result of an expression on two values. That is, the ternary operator is just abused to obtain the common type. The condition is immaterial, however.

    The relevant section in the standard is 5.16 [expr.cond] paragraph 3:

    Otherwise, if the second and third operand have different types and either has (possibly cv-qualified) class type, or if both are glvalues of the same value category and the same type except for cv-qualification, an attempt is made to convert each of those operands to the type of the other.

    Following the paragraph are the rules of how the common type is provided. The otherwise refers to the case that either the second or the third expression is throw-expression or one or both of the second or the third expression have type void.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like the one below: class Foo { private: std::map<std::string, Bar*>
I know that the below code is a partial specialization of a class: template
Why is it that in the code below template<typename T> struct Child : public
iam making one applciation.In that iam using the NSUrlconnection class.Below one is my code.
<div class='clear'></div> /*which comes out to be below one in FF (seen via firebug)
I have an xml document like the below one that I am trying to
I have a xml that looks like below one. I need your help to
i have a c++ class like the below one working at vc++ , but
Below is one of my C functiosn: void test(char * ptr) { ptr[0] =
Which one below is correct? First code has no quotes in the $_GET array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.