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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:13:56+00:00 2026-05-13T11:13:56+00:00

On page 340 of the C++ Programming Language: Special Edition, Stroustrup writes… The semantic

  • 0

On page 340 of the C++ Programming Language: Special Edition, Stroustrup writes…

The semantic checking of a default argument for a template parameter is done if and (only) when that default argument is actually used. In particular, as long as we refrain from using the default template argument Cmp<T> we can compare() strings of a type for which Cmp<X> wouldn't compile (say, because < wasn't defined for an X). This point is crucial in the design of the standard containers, which rely on a template argument to specify default values.

I’m having trouble wrapping my head around the usage of this. Why would this rule allow strings of type X to be compared, when normally it wouldn’t compile? Wouldn’t this behavior be undesirable?

  • 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-13T11:13:56+00:00Added an answer on May 13, 2026 at 11:13 am

    The given example is:

    template<class T, class C = Cmp<T> >
    int compare(const String<T>& str1, const String<T>& str2) 
    {
        // ... compare using C
    }
    

    The idea is that the class template Cmp might not be defined or illegal for some T. In that case, you can pass a custom comparison class template:

    compare<char, MyComparer>(str1, str2);
    

    If you do that, Cmp isn’t used and won’t be checked if it actually would compile.

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

Sidebar

Related Questions

Guys, I'm doing excercises from The C++ Programming Language 3rd ed. and on page
Page 120 of Programming Pearls 1st edition presents this algorithm for selecting M equally
Page 601 of the C++ Special Edition says... In <ctype.h> and <cctype>, the standard
From page 90 of Erlang Programming by Cesarini and Thomson, there is an example
page--node--edit.tpl.php works just fine when you want to create a specific template for editing
page.xml contains: <default translate=label module=page> <label>All Pages</label> <reference name=root> <action method=addBodyClass><className>testing</className></action> </reference> Yet it's
This page from Adobe says to add a wmode parameter and set its value
Page A has a meta refresh to redirect to another page, C , after
Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div
Page in question: http://phwsinc.com/our-work/one-rincon-hill.asp In IE6-8, when you click the left-most thumbnail in the

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.