Coder Social home page Coder Social logo

make_comparable's Introduction

Basics

When you make a comparable type you usually only need to implement operator <: c++ std::sort and containers use this operator only. But when you compare your type in other places, you want all operators for easy of use. Of course, you do not want to implement them by yourself, you want them to be implemented using your operator <. Well, here you are.

MakeComparable

MakeComparable is a c++ template than from a type with operator < (and possibly some other comparison operators) makes new type with full support of comparison: <, <=, >, >=, == and !=. C++ concepts and SFINAE make possible to use your existing operators and make new only for missing ones: for example, you may want to explicitly implement operator == and operator != for performance reasons.

Requirements

MakeComparable uses Concepts TS, so you need modern compiler to use it. gcc-6.1 or higher is ok, but you have to pass -fconcepts to it.

Usage

#include "make_comparable.h++"

class YourClassStub {
  public:
    bool operator < ( const YourClassStub & ) const;
    // You have to implement 'operator <' and you may (but do not have to) implement any other.
  ...
};

typedef make_comparable::MakeComparable <YourClassStub> YourClass;
// Now you have YouClass with six comparison operators, ready to use.

See also example.c++.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.