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

  • Home
  • SEARCH
  • 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 6079021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:58+00:00 2026-05-23T10:53:58+00:00

I started looking at std::common_type and am not exactly sure about its purpose and

  • 0

I started looking at std::common_type and am not exactly sure about its purpose and its functionality.
A few things still strike me as odd:

  • Order of arguments is important: common_type<Foo, Bar, Baz> might be different from common_type<Baz, Foo, Bar>. Either might compile, the other might not. While this is clear from the way common_type is defined, it feels strange and unintuitive. Is this for lack of a universal solution or intended?
  • Instantiation can result in a compiler error instead of something I can handle. How to check if common_type will actually compile? is_convertible is not enough as common_type might be specialized?
  • There is still no way to figure out the common type in a situation like this:

    struct Baz;
    struct Bar { int m; };
    struct Foo { int m; }; 
    struct Baz { Baz(const Bar&); Baz(const Foo&); };
    

    The recommended solution would be to specialize common_type which is tedious. Is there a better solution?

For reference see §20.9.7.6 Table 57 in N3242.

  • 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-05-23T10:53:59+00:00Added an answer on May 23, 2026 at 10:53 am

    std::common_type was introduced for use with std::duration — if you add a std::duration<int> and a std::duration<short> then the result should be std::duration<int>. Rather than specifying an endless stream of allowed pairings, the decision was made to delegate to a separate template which found the result using the core language rules applicable to the ?: arithmetic-if operator.

    People then saw that this template might be generally useful, and it was added as std::common_type, and extended to handle an arbitrary number of types. In the C++0x library it is only used for pairs of types though.

    You should be able to use the new SFINAE rules to detect whether or not some instantiation of std::common_type is valid. I haven’t tried though. In most cases if there isn’t a “common type” then there isn’t anything meaningful you can do anyway, so a compile error is reasonable.

    std::common_type is not magic — it follows the rules of ?:. If true?a:b will compile, std::common_type<decltype(a),decltype(b)>::type will give you the type of the result.

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

Sidebar

Related Questions

I've just started looking at hooks today not 100% sure what I'm doing wrong
I've started looking into a few larger server-app frameworks that would be able to
I've installed PowerShell recently and one of the first things I started looking for
So I've started looking at ruby, and a lot of things look nice but
I've started looking at jQuery's built-in tabs functionality here: http://docs.jquery.com/UI/Tabs Is there any way
I've started looking into Appcelerator 1.8.0 few days and back and i'm a little
I need a cheat sheet for Java and started looking around, but could not
I started looking at Silverlight.FX by Nikhil Kothari to replace Prism/Unity with our Silverlight
I have recently started looking into Google Charts API for possible use within the
When I first started looking into Rails and Django I was steered away from

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.