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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:17:09+00:00 2026-06-18T10:17:09+00:00

How do I get operators > , >= , <= , and != from

  • 0

How do I get operators >, >=, <=, and != from == and <?

standard header <utility> defines a namespace std::rel_ops that defines the above operators in terms of operators == and <, but I don’t know how to use it (coax my code into using such definitions for:

std::sort(v.begin(), v.end(), std::greater<MyType>); 

where I have defined non-member operators:

bool operator < (const MyType & lhs, const MyType & rhs);
bool operator == (const MyType & lhs, const MyType & rhs);

If I #include <utility> and specify using namespace std::rel_ops; the compiler still complains that binary '>' : no operator found which takes a left-hand operand of type 'MyType'..

  • 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-18T10:17:10+00:00Added an answer on June 18, 2026 at 10:17 am

    I’d use the <boost/operators.hpp> header :

    #include <boost/operators.hpp>
    
    struct S : private boost::totally_ordered<S>
    {
      bool operator<(const S&) const { return false; }
      bool operator==(const S&) const { return true; }
    };
    
    int main () {
      S s;
      s < s;
      s > s;
      s <= s;
      s >= s;
      s == s;
      s != s;
    }
    

    Or, if you prefer non-member operators:

    #include <boost/operators.hpp>
    
    struct S : private boost::totally_ordered<S>
    {
    };
    
    bool operator<(const S&, const S&) { return false; }
    bool operator==(const S&, const S&) { return true; }
    
    int main () {
      S s;
      s < s;
      s > s;
      s <= s;
      s >= s;
      s == s;
      s != s;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Declarations of auto_ptr from C++ Standard Library namespace std { template <class Y> struct
When trying to build a simple test program that uses atomic operations, I get
Get class from div inside an li and add to the same li. The
I have a web api set up to get companies from a data base.
Possible Duplicate: Goto out of a block: do destructors get called? I know that
I have a class that looks like this: typedef std::list<char*> PtrList; class Foo {
I'm developing a system that operates on (arbitrary) data from databases. The data may
from the javadoc for java.lang.Process : The methods that create processes may not work
I get a Decorated name length exceeded warning from my code I've looked at
My assignment is to make a class that acts like a standard library List

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.