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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:15:59+00:00 2026-05-26T11:15:59+00:00

I was reading the documentation of std::sub_match<BidirectionalIterator> and saw that it publicly inherits from

  • 0

I was reading the documentation of std::sub_match<BidirectionalIterator> and saw that it publicly inherits from std::pair<BidirectionalIterator, BidirectionalIterator>. Since a sub_match is simply a pair of iterators into a sequence of characters, with some additional functions, I can understand that it is implemented with a pair, but why use public inheritance?

The problem with inheriting publicly from std::pair<T,U> is the same as inheriting publicly from most other standard classes: they are not meant to be manipulated polymorphically (notably they do not define a virtual destructor). Other members will also fail to work properly, namely the assignment operator and the swap member function (they will not copy the matched member of sub_match).

Why did Boost developers and then the committee decided to implement sub_match by inheriting publicly from pair instead of using composition (or private inheritance with using declarations if they wanted to keep member access through first and second)?

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

    It’s an interesting question. Presumably, they considered it safe
    because no one would ever dynamically allocate one anyway. About the
    only way you’re going to get sub_match objects is as a return value
    from some of the functions of basic_regex, or as copies of other
    sub_match, and all of these will be either temporaries or local
    variables.

    Note that it’s not safe to keep sub_match objects around anyway, since
    they contain iterators whose lifetime… doesn’t seem to be specified in
    the standard. Until the match_results object is reused? Until the
    string operand to the function which filled in the match_results
    object is destructed? Or?

    I’d still have avoided the public inheritence. But in this case, it’s
    not as dangerous as it looks, because there’s really no reason you’d
    ever want to dynamically allocate a sub_match.

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

Sidebar

Related Questions

From reading the documentation Jekyll's template data one might think that the way to
While reading documentation on some library, I saw that some library have some feature,
Reading the documentation it seems this might not be possible, but it seems that
I'm reading this documentation article about Custom Annotations in Doctrine . I understand that
I'm new to HTML. When I started reading documentation about lists, I've noticed that
Reading Apple documentation i found that UIEventTypeMotion is useful only to intercept Shake. It
Reading documentation about fileReader , and find out that they write methods using void
I have been reading documentation about the new features that IIS 7.5 offers regarding
As I understand from reading documentation, UIPopoverControllers are only supported on the iPad. Therefore
After reading documentation of underscore.js I found (to my surprise) that actually not all

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.