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

The Archive Base Latest Questions

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

For example, I want to write overload functions for set_difference which compares the type

  • 0

For example, I want to write overload functions for set_difference which compares the type std::set<point>

class myIter : public std::iterator<std::input_iterator_tag, int> {
public:
    myIter(int n) : num(n){}
    myIter(const myIter & n) : num(n.num){}
    int & operator *(){return num;}
    myIter & operator ++(){++num; return *this;}
    bool operator !=(const myIter & n){return n.num != num;}
private:
    int num;
};

struct point
{
  point(int X, int Y):x(X), y(Y){}
  int x;
  int y;
}

int main()
{
   set <point> myset;
   myset.insert(point(1, 1);
   myset.insert(point(3, 2);
   myset.insert(point(5, 3);

  //find the missing elements in set for `point.x` using `set_difference`

   std::set<int> missing;

   std::set_difference(myIter(myset.begin()->x+1), myIter(myset.rbegin()->x),
   myset.begin(), myset.end(), std::insert_iterator<std::set<int>>(missing, missing.begin()));

}

After applying the std::set_difference on point.x variables the set<int> missing must be:

missing[0] {2}
missing[1] {4}

How do i know how to write the overload operators for the operation?

  • 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-16T16:59:26+00:00Added an answer on May 16, 2026 at 4:59 pm

    Firstly, std::set<point> requires that point is less-than-comparable. You can either define operator< for point, or provide a separate function object that does the comparison as the second template parameter std::set<point,MyCompare>.

    Once you actually have your elements in the set, you can use set_difference. It’s worth noting that set_difference doesn’t actually require you to use std::set for your input — you could just use a vector and thus avoid having to provide the comparison function.

    To use set_difference, you will need to ensure that the value_types of the two iterator ranges are the same, so you’ll need another iterator wrapper that returns just the x portion of the point values for the second range.

    std::set_difference(myIter(myset.begin()->x+1), myIter(myset.rbegin()->x),
        extractXIter(myset.begin()), extractXIter(myset.end()),
        std::insert_iterator<std::set<int>>(missing, missing.begin()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to use absolute path: SET(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/test.sh") This is… May 16, 2026 at 6:04 pm
  • Editorial Team
    Editorial Team added an answer I would probably call it matchingAccuracy, matchingPrecision or something like… May 16, 2026 at 6:04 pm
  • Editorial Team
    Editorial Team added an answer As you said, the behaviour you're describing is the password… May 16, 2026 at 6:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to write a test case which will test a list of functions.
Suppose I want to write a function like the following (as usual, a trivial
Is it possible to overload the array/dict access operators in VB.net? For example, you
I'm using yaml-cpp for a project. I want to overload the << and >>
I'm trying to write a method like this: public static T Test<T>() { if
I want to write a program to add all the digits of the entered
I want to write a program for finding out the sum of first and
I want to write a method in Java that verifies that some conditions hold
If I want to write a custom command for a button control in WPF,
I want to send a GET web Request to a WCF service: for example

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.