GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rollbear/dry-comparisons: C++17 Utility classes for comparing multiple values in one simple expression

BranchesTags
Open more actions menu

Latest commit

 

History

57 Commits
57 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.gitignore
.gitignore
 
 
CMakeLists.txt
CMakeLists.txt
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
dry-comparisons.hpp
dry-comparisons.hpp
 
 
self_test.cpp
self_test.cpp
 
 

Repository files navigation

dry-comparisons

CI codecov

This is the source code for the any_of, all_of and none_of C++17 utility mentioned in the blog post "DRY multicomparisons"

Public domain.

Usage

using rollbear::any_of;

class Machine
{
public:
  ...
  void func() {
    assert(state == any_of(S1, S3)); // assert(state == S1 || state == S3);
    ...
  }
private:
  enum { S0, S1, S2, S3 } state;
};

The types available are any_of, all_of and none_of.

iff all member types can be inserted into an ostream, an instance of any_of, all_of or none_of may be printed, e.g. std::cout << rollbear::any_of{1,3,5}, which will produce the output any_of{1,3,5}.

iff it is possible to do logical and/or operations on all members, instances of any_of, all_of and none_of may be used directly as boolean expressions.

  • bool(any_of{a,b,c}) == bool(a || b || c)
  • bool(all_of{a,b,c}) == bool(a && b && c)
  • bool(none_of{a,b,c}) == !bool(a || b || c)

iff the members are callable, the resulting object is also callable.

  • any_of{std::plus{}, std::minus{}}(3,2) == 5
  • all_of{std::plus{}, std::minus{}}(3,2) > 0
  • none_of{std::plus{}, std::minus{}}(3,2) == 0

with SFINAE friendly checks that the calls can be made for the values given. The logical conditions are short cirquited, in the normal logical expression manners.

Further more, it is also possible to do relational comparisons. For example:

assert(all_of(s1, s2) > "."), providing the expressions s1 and s2 are greater-than comparable with a string literal.

About

C++17 Utility classes for comparing multiple values in one simple expression

Resources

Readme
Unlicense
Activity

Stars

208 stars

Watchers

10 watching

Forks

13 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.