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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:47:40+00:00 2026-06-15T05:47:40+00:00

How would I implement a operator< for line segments that consist of a start

  • 0

How would I implement a operator< for line segments that consist of a start and a end Point. I want to insert the line segments into a map so the order doesn’t need to be semantic, but it should work for all cases.

  • 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-15T05:47:43+00:00Added an answer on June 15, 2026 at 5:47 am

    Order everything lexicographically:

    struct Point { int x; int y; };
    
    bool operator<(Point const & a, Point const & b)
    {
        return (a.x < b.x) || (!(b.x < a.x) && (a.y < b.y));
    }
    

    Or use the ready made comparator from tuple:

    #include <tuple>
    
    // ...
    
    return std::tie(a.x, a.y) < std::tie(b.x, b.y);
    

    Or actually use a std::tuple<int, int> for your points and do nothing at all!

    Then, do the same for the lines:

    struct LineSegment { Point x; Point y; };
    
    // repeat same code as above, e.g.
    
    bool operator<(LineSegment const & a, LineSegment const & b)
    {
        return std::tie(a.x, a.y) < std::tie(b.x, b.y);
    }
    

    To repeat, the no-work-at-all solution just uses tuples all the way:

    typedef std::tuple<int, int> Point;
    typedef std::tuple<Point, Point> LineSegment;
    // everything "just works"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement operator * overloading INSIDE my class, so I would be
How would you implement a Listener that is queuing events that are executed at
How would you implement a capacity-limited, generic MruList in C# or Java? I want
Possible Duplicates: How would I implement stackoverflow’s hovering dialogs? i want a small box
Some time ago I was asked the strange question how would I implement map
Possible Duplicate: implement division with bit wise operator I recently got into more depth
I can not implement >> operator ostream&operator>>(Mode&refMode,ostream&os) to perform chaining operations as refMode.iMode>>(refMode.jMode>>os) Would
I would like to have a class implement operator() several different ways based on
How would one implement a ternary comparison operator to determine, for example, the boolean
looking at dribbble, I have started to ask myself, how I would implement 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.