cp-documentation

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

View the Project on GitHub zawa-tin/cp-documentation

:heavy_check_mark: min演算モノイド
(Src/Algebra/Monoid/MinMonoid.hpp)

概要

std::optional<T>を利用して、 $\infty$ を std::nulloptで表現している。

std::optional<T>の運用については std::optional cpprefjp 等も参考にすること。

Verified with

Code

#pragma once

#include <algorithm>
#include <optional>

namespace zawa {

template <class T>
class MinMonoid {
public:
    using Element = std::optional<T>;
    static constexpr Element identity() noexcept {
        return std::nullopt;
    }
    static constexpr Element operation(const Element& l, const Element& r) noexcept {
        if (l and r) {
            return std::min(l, r);
        }
        else if (l) {
            return l;
        }
        else if (r) {
            return r;
        }
        else {
            return std::nullopt;
        }
    }
};

} // namespace zawa
#line 2 "Src/Algebra/Monoid/MinMonoid.hpp"

#include <algorithm>
#include <optional>

namespace zawa {

template <class T>
class MinMonoid {
public:
    using Element = std::optional<T>;
    static constexpr Element identity() noexcept {
        return std::nullopt;
    }
    static constexpr Element operation(const Element& l, const Element& r) noexcept {
        if (l and r) {
            return std::min(l, r);
        }
        else if (l) {
            return l;
        }
        else if (r) {
            return r;
        }
        else {
            return std::nullopt;
        }
    }
};

} // namespace zawa
Back to top page