change
| 投稿者 | Mizar |
|---|---|
| 言語 | Rust |
| 更新日時 (JST) | 2026-10-17 18:20:05 |
| サイズ | 480 Byte |
| 参照URL | |
日時はサーバーが記録したものです。更新すると更新日時が変わるので、不都合がある場合は新しく投稿してください。
/// chmax, chmin sugar syntax
pub trait Change {
fn chmax(&mut self, x: Self) -> bool;
fn chmin(&mut self, x: Self) -> bool;
}
impl<T: PartialOrd> Change for T {
fn chmax(&mut self, x: T) -> bool {
if *self < x {
*self = x;
true
} else {
false
}
}
fn chmin(&mut self, x: T) -> bool {
if *self > x {
*self = x;
true
} else {
false
}
}
}