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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:38:03+00:00 2026-06-14T23:38:03+00:00

I have a multiset and I’m getting a range from it. I want to

  • 0

I have a multiset and I’m getting a range from it. I want to add this range in a vector to use it later, this is what I’m doing:

class foo
{
    public:
        int a;
        foo(int a) : a(a){}
};
class FooPointerCompare
{
    public:
        bool operator()(const foo* a, const foo* b)
        {
            return a->a < b->a;
        }
};

std::multiset<foo*, FooPointerCompare> m;
std::vector<std::multiset<foo*, FooPointerCompare>::iterator> v;
auto pair = m.equal_range(new foo(5)); //leak here, I know
v.insert(v.end(), pair.first, pair.second);

but I get these errors:

No matching constructor for initialization of 'std::__1::__tree_const_iterator<foo *, const std::__1::__tree_node<foo *, void *> *, int>'

No viable overloaded '='

when I use a simple for(auto it = pair.first; it != pair.second; it++) v.push_back(it); it works perfectly. What is wrong with my vector::insert call?

  • 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-14T23:38:04+00:00Added an answer on June 14, 2026 at 11:38 pm

    What’s wrong is that

    v.insert(v.end(), pair.first, pair.second);
    

    is equivalent to

    for (auto it = pair.first; it != pair.second; ++ it)
        v.push_back(*it);
    //              ^
    

    which is not the same as your intention. I don’t think there’s any standard algorithms to do what you want. It’s better you just write out the for loop.

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

Sidebar

Related Questions

I have a std::multiset which stores elements of class A . I have provided
have written this little class, which generates a UUID every time an object of
Have a photography site that I want to prevent image copying from. How can
I have this: struct myClass{ multiset<string,binPred<string> > values ; myClass(const char param1, const char
Good afternoon, I have a C++ class Range which implements a operator < for
I have a set, namely of type multiset , I'm trying to use the
How to count values in a multiset? I have a dataset and i want
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have: 1) a starting set, a multiset, e.x. { x, y, z, z
Have finally got a responsive site working (of a fashion). What I want to

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.