和と長さを得る演算のモノイド (utility/monoid/length.cpp)
- category: utility/monoid
-
View this file on GitHub
- Last commit date: 2020-03-22 02:59:14+09:00
Required by
- 作用のヘルパークラス (misc/interface/action.cpp)
- 区間和・区間加算用のヘルパークラス (utility/action/add_sum.cpp)
- 区間 Affine 変換・区間加算用のヘルパークラス (utility/action/affine_sum.cpp)
- 区間和・区間代入用のヘルパークラス (utility/action/set_sum.cpp)
Verified with
- test/aoj_DSL_2_G.test.cpp
- test/aoj_DSL_2_I.test.cpp
- test/aoj_GRL_5_E.test.cpp
- test/yj_range_affine_range_sum.test.cpp
Code
/**
* @brief 和と長さを得る演算のモノイド
* @author えびちゃん
*/
#include <cstddef>
#include <utility>
#ifndef H_length_monoid
#define H_length_monoid
template <typename Tp>
class length_monoid {
public:
using value_type = Tp;
using size_type = size_t;
private:
value_type M_x{};
size_type M_l = 1;
public:
length_monoid() = default; // identity
length_monoid(value_type const& x, size_type l = 1): M_x(x), M_l(l) {};
length_monoid(value_type&& x, size_type l = 1): M_x(std::move(x)), M_l(l) {};
length_monoid& operator +=(length_monoid const& that) {
M_x += that.M_x;
M_l += that.M_l;
return *this;
}
length_monoid& operator +=(length_monoid&& that) {
M_x += std::move(that.M_x);
M_l += that.M_l;
return *this;
}
length_monoid operator +(length_monoid const& that) const {
return length_monoid(*this) += that;
}
length_monoid operator +(length_monoid&& that) const {
return length_monoid(*this) += std::move(that);
}
value_type const& get() const { return M_x; }
size_type length() const { return M_l; }
};
#endif /* !defined(H_length_monoid) */
#line 1 "utility/monoid/length.cpp"
/**
* @brief 和と長さを得る演算のモノイド
* @author えびちゃん
*/
#include <cstddef>
#include <utility>
#ifndef H_length_monoid
#define H_length_monoid
template <typename Tp>
class length_monoid {
public:
using value_type = Tp;
using size_type = size_t;
private:
value_type M_x{};
size_type M_l = 1;
public:
length_monoid() = default; // identity
length_monoid(value_type const& x, size_type l = 1): M_x(x), M_l(l) {};
length_monoid(value_type&& x, size_type l = 1): M_x(std::move(x)), M_l(l) {};
length_monoid& operator +=(length_monoid const& that) {
M_x += that.M_x;
M_l += that.M_l;
return *this;
}
length_monoid& operator +=(length_monoid&& that) {
M_x += std::move(that.M_x);
M_l += that.M_l;
return *this;
}
length_monoid operator +(length_monoid const& that) const {
return length_monoid(*this) += that;
}
length_monoid operator +(length_monoid&& that) const {
return length_monoid(*this) += std::move(that);
}
value_type const& get() const { return M_x; }
size_type length() const { return M_l; }
};
#endif /* !defined(H_length_monoid) */