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

The Archive Base Latest Questions

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

std::set_union and its kin take two pairs of iterators for the sets to be

  • 0

std::set_union and its kin take two pairs of iterators for the sets to be operated on. That’s great in that it’s the most flexible thing to do. However they very easily could have made an additional convenience functions which would be more elegant for 80% of typical uses.

For instance:

template<typename ContainerType, typename OutputIterator>
OutputIterator set_union( const ContainerType & container1, 
                const ContainerType & container2, 
                OutputIterator      & result      )
{
    return std::set_union( container1.begin(), container1.end(), 
                           container2.begin(), container2.end(), 
                           result );
}

would turn:

std::set_union( mathStudents.begin(), mathStudents.end(), 
                physicsStudents.begin(), physicsStudents.end(), 
                students.begin() );

into:

std::set_union( mathStudents, physicsStudents, students.begin() );

So:

  • Are there convenience functions like this hiding somewhere that I just haven’t found?

  • If not, can anyone thing of a reason why it would be left out of STL?

  • Is there perhaps a more full featured set library in boost? (I can’t find one)

I can of course always put my implementations in a utility library somewhere, but it’s hard to keep such things organized so that they’re used across all projects, but not conglomerated improperly.

  • 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-23T16:20:53+00:00Added an answer on May 23, 2026 at 4:20 pm

    Are there convenience functions like this hiding somewhere that I just haven’t found?

    Not in the standard library.

    If not, can anyone thing of a reason why it would be left out of STL?

    The general idea with algorithms is that they work with iterators, not containers. Containers can be modified, altered, and poked at; iterators cannot. Therefore, you know that, after executing an algorithm, it has not altered the container itself, only potentially the container’s contents.

    Is there perhaps a more full featured set library in boost?

    Boost.Range does this. Granted, Boost.Range does more than this. It’s algorithms don’t take “containers”; they take iterator ranges, which STL containers happen to satisfy the conditions for. They also have lazy evaluation, which can be nice for performance.

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

Sidebar

Related Questions

Given two std::set s, one can simply iterate through both sets simultaneously and compare
What's the return of the algorithm std:set_union when one or both input containers are
s1 and s2 are sets (Python set or C++ std::set) To add the elements
How do I check for the empty intersection of two std::set s? I can
I have a couple questions about how to use C++ sets (std::set) Is there
I Have two sets of strings. set<string> A; set<string> B; I will insert some
I have an std::set and I wanted to iterate trough the element pairs in
I have some C++ methods that have std::set<std::string> as argument or return value. I
From cplusplus.com reference it seems that std::set sorts elements. I need to have sorted
I'm adding two different elements to both std::list and std::set and I want 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.