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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:43:08+00:00 2026-06-14T20:43:08+00:00

typedef struct Edge { int v1, v2, w; bool operator <(const Edge &rhs) const{

  • 0
typedef struct Edge
{
    int v1, v2, w;
    bool operator <(const Edge &rhs) const{
        bool b = v1 < rhs.v1 || v2 < rhs.v2;
        return (b);
    }
} edge;


template <class T>
struct my_less
{
    bool operator()(const T& _Left, const T& _Right) const
    {
        return (_Left < _Right);
    }
};

int main(int argc, char *argv[])
{
    set <edge, my_less<edge> > F;

    edge e3 = { 3, 3, 3};
    edge e4 = { 3, 7, 3};
    edge e5 = { 2, 7, 3};

    F.insert(e3);
    printf("e3 ? %d\n", F.find(e3)!=F.end()); // O
    printf("e4 ? %d\n", F.find(e4)!=F.end()); // O
    printf("e5 ? %d\n", F.find(e5)!=F.end()); // X

    //printf("%d\n", e3<e4);

    return 0;
}
If run this code, I got an error at "F.find(e5)!=F.end()" with following message.
"Debug Assertion Failed!. Expression: invalid operator < "

The condition of two edges of '(x,y), (p,q)' equality is 
 !(x < p || y < q) && !(p < x || q < y)

It can be '(x>=p && y>=q) && (p>=x && q>=y)'

I really don't know why assertion raised.
Is there something wrong?
  • 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-14T20:43:10+00:00Added an answer on June 14, 2026 at 8:43 pm

    Your comparison doesn’t enforce a strict ordering. For example:

    Edge e1;
    Edge e2;
    
    e1.v1 = 5;
    e1.v2 = 4;
    
    e2.v1 = 4;
    e2.v2 = 5;
    
    // e1 < e2 is true
    // e2 < e1 is true
    // So which one should we really trust? Neither, let's abort the program!
    

    You need to make your < operator actually work like < should. If e1 < e2 is true, then e2 < e1 needs to be false.

    I think this might be what you want, but beware that I haven’t tested it:

    return v1 < rhs.v1 || (v1 == rhs.v1 && v2 < rhs.v2);
    

    This should, in theory, sort by v1, and use v2 to break ties.

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

Sidebar

Related Questions

typedef struct { int data1; float data2; } packetType1; typedef struct { bool data1;
typedef struct _wax_instance_userdata { id instance; BOOL isClass; Class isSuper; BOOL actAsSuper; } wax_instance_userdata;
const int ADJ_MATRIX[VERTEX_NUM][VERTEX_NUM]={ {0,1,1,0,0,0,0,0}, {1,0,0,1,1,0,0,0}, {1,0,0,0,0,1,1,0}, {0,1,0,0,0,0,0,1}, {0,1,0,0,0,0,0,1}, {0,0,1,0,0,0,1,0}, {0,0,1,0,0,1,0,0}, {0,0,0,1,1,0,0,0} }; typedef struct
I have a structure: typedef struct stock { const char* key1p2; // stock code
From objc.h: typedef struct objc_class *Class; but in runtime.h: struct objc_class { Class isa;
Consider the following: typedef struct { int a; int b; int c; int d;
I have these structs: typedef struct _Frag{ struct _Frag *next; char *seq; int x1;
I have a struct typedef struct { int id; string name; string address; string
I have a structure typedef struct store { char name[11]; int age; } store;
I have the following code: typedef struct AdjMatrix { int nodes; int **adjMat; }

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.