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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:55+00:00 2026-05-26T18:05:55+00:00

I am trying to find the difference between the following two sets: A =

  • 0

I am trying to find the difference between the following two sets:

A = {(0,0), (0,1), (1,0), (1,1), (2,2)}

B = {(0,0), (0,1), (1,0), (1,1)}

The answer I am expecting is

A - B = {(2,2)}

I tried the following code. But I am stuck unable to compile. Can anyone point out the mistake I am making?

#include <vector>
#include <algorithm>
#include <iostream>
#include <utility>

using namespace std;

class compare
{
  public:
    bool operator()(const pair <int, int> elem1, const pair <int, int> elem2)
    {
      return ((elem1.first == elem2.first) && 
          (elem1.second == elem2.second));
    }
};

int main()
{
  vector < pair<int, int> > v, va, vb;
  va.push_back(make_pair(0,0));
  va.push_back(make_pair(0,1));
  va.push_back(make_pair(1,0));
  va.push_back(make_pair(1,1));
  va.push_back(make_pair(2,2));

  vb.push_back(make_pair(0,0));
  vb.push_back(make_pair(0,1));
  vb.push_back(make_pair(1,0));
  vb.push_back(make_pair(1,1));


  vector < pair<int, int> >::iterator it, result;
  result = set_difference (va.begin(), va.end(),
      vb.begin(), vb.end(), 
      inserter(v, v.end()), 
      compare());

  // for (it = v.begin( ) ; it != result; it++)
  //   cout << "(" << it->first << it->second << ")" << ", ";
  // cout << endl;

  return 0;
}

EDIT:
The compile error message is the following:

set_difference.cc: In function `int main()':
set_difference.cc:36: error: no match for 'operator=' in 'result = std::set_difference [with _InputIterator1 = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >, _InputIterator2 = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >, _OutputIterator = std::insert_iterator<std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >, _Compare = compare]((&va)->std::vector<_Tp, _Alloc>::begin [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >](), (&va)->std::vector<_Tp, _Alloc>::end [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >](), (&vb)->std::vector<_Tp, _Alloc>::begin [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >](), (&vb)->std::vector<_Tp, _Alloc>::end [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >](), std::inserter [with _Container = std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >, _Iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >](((std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >&)(&v)), (&v)->std::vector<_Tp, _Alloc>::end [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >]()), (compare(), compare()))'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_iterator.h:587: note: candidates are: __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >& __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >::operator=(const __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > > >&)
  • 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-26T18:05:56+00:00Added an answer on May 26, 2026 at 6:05 pm

    OK, now with the error message posted it’s clear what is the problem:
    set_difference returns the output iterator, which in this case is an insert_iterator (constructed by your call to inserter). You try to assign it to result which is a vector iterator. This is a type mismatch.

    The simplest solution would be to just omit that assignment and the iterator result because you don’t need that iterator anyway; the results have been written to v.

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

Sidebar

Related Questions

Im trying to see a performance difference between the following two programs (was expecting).
I am trying to calculate the difference between given two times and i find
I have been trying to find out what the difference is between the IS
I am trying to understand the difference between matches() and find() . According to
I am trying to find the difference in days between the current date and
Trying to find some information on this but am unable to get any results
Trying to find the sqlserver adapter for rails on windows. I have tried getting
I have been trying to find info on the web about the differences between
I'm trying to find the differences between SwingWorker execute() vs doInBackground().So I have written
I'm trying to find a good way to maintain PHP configuration differences between a

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.