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 8793293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:06:15+00:00 2026-06-13T23:06:15+00:00

in book The Cpp standard library, 2nd edition, by Nicolai M. Josuttis, says (5.4,

  • 0

in book “The Cpp standard library”, 2nd edition, by Nicolai M. Josuttis, says (5.4, p.125) that definition of struct common type is following:

template <typename T1, typename T2>
struct common_type<T1,T2> {
typedef decltype(true ? declval<T1>() : declval<T2>()) type;
};

I have serious problems to believe that this is correct definition of common_type. Reason:

typedef decltype(true ? declval<T1>() : declval<T2>()) type;//As far as I understand this will always pick second operand, declval<T1>(), due to the fact that there is 'true' value. Am I right?
  • 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-13T23:06:16+00:00Added an answer on June 13, 2026 at 11:06 pm

    It’s all about conditional operator. It isn’t selection statement like if or switch.

    5.16 paragraph of ISO C++11 standard:

    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.

    So, it doesn’t matter that decltype contains true condition, compiler have to choose common type as result.

    UPD: 5.16 contains further description of correct behavior, you should see it for completely understanding entire process. But for your particular question:

    Using this process, it is determined whether the second operand can be
    converted to match the third operand, and whether the third operand
    can be converted to match the second operand. If both can be
    converted, or one can be converted but the conversion is ambiguous,
    the program is ill-formed. If neither can be converted, the operands
    are left unchanged and further checking is performed as described
    below. If exactly one conversion is possible, that conversion is
    applied to the chosen operand and the converted operand is used in
    place of the original operand for the remainder of this section.

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

Sidebar

Related Questions

The book I am reading says that after allocating an object I need to
One Book(Object Oriented Programming with C++ by E.Balagurusamy) says that const size = 10;
I have read in a book that specifies this : //: C03:SimpleCast.cpp int main()
Q1 Book suggests that before we register new SqlProfileProvider , we should remove any
The book, Producing Open Source Software , suggests that it's better to have lengthy
The book says about a small Windows.Forms program The Windows Forms classes are in
So, I'm reading this book: C++ GUI Programming with Qt 4, Second Edition by
I've been teaching myself cpp sporadically from 'accelerated C++' and recently I noticed that
I'm doing a homework and I'm trying to follow a class diagram. In Book.cpp
I am reading the book "Exceptional C++" by Herb Sutter, and in that book

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.