Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Negate_Compare< T, Compare > Class Template Reference

Comparator wrapper that inverts the comparison order. More...

#include <tpl_sort_utils.H>

Public Member Functions

 Negate_Compare (Compare __cmp=Compare()) noexcept(std::is_nothrow_copy_assignable_v< Compare >)
 Construct from a comparator.
 
bool operator() (const T &e1, const T &e2) const noexcept(noexcept(std::declval< const Compare & >()(e2, e1)))
 Compare in reverse order: returns cmp(e2, e1).
 

Private Attributes

Compare cmp
 

Detailed Description

template<typename T, class Compare>
class Aleph::Negate_Compare< T, Compare >

Comparator wrapper that inverts the comparison order.

Given a comparator cmp, this wrapper creates a comparator that returns cmp(e2, e1) instead of cmp(e1, e2). This is useful for converting a min-heap algorithm to a max-heap algorithm.

Template Parameters
TElement type being compared.
CompareThe underlying comparator type.
See also
heapsort()

Definition at line 2948 of file tpl_sort_utils.H.

Constructor & Destructor Documentation

◆ Negate_Compare()

template<typename T , class Compare >
Aleph::Negate_Compare< T, Compare >::Negate_Compare ( Compare  __cmp = Compare())
inlinenoexcept

Construct from a comparator.

Definition at line 2954 of file tpl_sort_utils.H.

Member Function Documentation

◆ operator()()

template<typename T , class Compare >
bool Aleph::Negate_Compare< T, Compare >::operator() ( const T e1,
const T e2 
) const
inlinenoexcept

Compare in reverse order: returns cmp(e2, e1).

Definition at line 2961 of file tpl_sort_utils.H.

References Aleph::Negate_Compare< T, Compare >::cmp, and Aleph::maps().

Member Data Documentation

◆ cmp

template<typename T , class Compare >
Compare Aleph::Negate_Compare< T, Compare >::cmp
private

Definition at line 2950 of file tpl_sort_utils.H.

Referenced by Aleph::Negate_Compare< T, Compare >::operator()().


The documentation for this class was generated from the following file: