m1une's library

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:warning: monoid/monoids/minmax_monoid.hpp

Depends on

Required by

Code

#ifndef M1UNE_MINMAX_MONOID_HPP
#define M1UNE_MINMAX_MONOID_HPP 1

#include <algorithm>
#include <limits>
#include <utility>

#include "../monoid.hpp"

namespace m1une {

// Monoid for storing both a minimum and maximum value.
// The operation combines two pairs by taking the component-wise min and max.
template <typename T>
using minmax_monoid =
    monoid<std::pair<T, T>,
           [](std::pair<T, T> a, std::pair<T, T> b) {
               return std::pair<T, T>(std::min(a.first, b.first), std::max(a.second, b.second));
           },
           []() { return std::pair<T, T>(std::numeric_limits<T>::max(), std::numeric_limits<T>::lowest()); }, true>;

}  // namespace m1une

#endif  // M1UNE_MINMAX_MONOID_HPP
#line 1 "monoid/monoids/minmax_monoid.hpp"



#include <algorithm>
#include <limits>
#include <utility>

#line 1 "monoid/monoid.hpp"



#include <concepts>
#include <functional>
#include <type_traits>

namespace m1une {

template <typename T, auto operation, auto identity, bool commutative>
struct monoid {
    static_assert(std::is_invocable_r_v<T, decltype(operation), T, T>, "operation must work as T(T, T)");
    static_assert(std::is_invocable_r_v<T, decltype(identity)>, "identity must work as T()");

    using value_type = T;
    static constexpr auto op = operation;
    static constexpr auto id = identity;
    static constexpr bool is_commutative = commutative;
};

template <typename T>
concept Monoid = requires(typename T::value_type v) {
    typename T::value_type;
    { T::op(v, v) } -> std::same_as<typename T::value_type>;
    { T::id() } -> std::same_as<typename T::value_type>;
    { T::is_commutative } -> std::convertible_to<bool>;
};

}  // namespace m1une


#line 9 "monoid/monoids/minmax_monoid.hpp"

namespace m1une {

// Monoid for storing both a minimum and maximum value.
// The operation combines two pairs by taking the component-wise min and max.
template <typename T>
using minmax_monoid =
    monoid<std::pair<T, T>,
           [](std::pair<T, T> a, std::pair<T, T> b) {
               return std::pair<T, T>(std::min(a.first, b.first), std::max(a.second, b.second));
           },
           []() { return std::pair<T, T>(std::numeric_limits<T>::max(), std::numeric_limits<T>::lowest()); }, true>;

}  // namespace m1une
Back to top page