Back to listC++
Abseil StatusOr Pattern
Lv.5361@mukitaro0 playsJan 2, 2026
Google Abseil StatusOr pattern. Either contains a value or an error status.
preview.cpp
1template <typename T>2class StatusOr {3 public:4 StatusOr(const T& value)5 : value_(value), ok_(true) {}6 StatusOr(Status status)7 : status_(status), ok_(false) {}8 bool ok() const { return ok_; }9 const T& value() const { return value_; }10 const Status& status() const {11 return status_;12 }13 private:14 T value_;15 Status status_;16 bool ok_;17};Custom problems are not included in rankings