5 #ifndef LODESTAR_STATUSOR_HPP
6 #define LODESTAR_STATUSOR_HPP
13 template<
typename TType>
16 template<
typename>
friend
30 template<
typename TTypeOther>
32 typename std::enable_if<std::is_convertible<TTypeOther, TType>::value>::type * =
nullptr);
34 template<
typename TTypeOther>
36 typename std::enable_if<!std::is_convertible<TTypeOther, TType>::value>::type * =
nullptr);
40 template<
typename TTypeOther>
41 typename std::enable_if<std::is_convertible<TTypeOther, TType>::value,
StatusOr &>::type
44 status_ = other.status_;
46 value_ = other.value_;
51 template<
typename TTypeOther>
52 typename std::enable_if<!std::is_convertible<TTypeOther, TType>::value,
StatusOr &>::type
55 static_assert(std::is_convertible<TTypeOther, TType>::value,
56 "StatusOr value must be convertible.");
61 const Status &status()
const;
65 inline explicit operator bool()
const;
67 const TType &value()
const;
74 template<
typename TType>
78 template<
typename TType>
79 inline StatusOr<TType>::StatusOr(
const Status &status)
82 status_ = util::InternalError();
87 template<
typename TType>
88 inline StatusOr<TType>::StatusOr(
const TType &value)
90 if (!std::is_pointer<decltype(&value)>::value)
91 status_ = util::InternalError();
93 status_ = util::OkStatus();
98 template<
typename TType>
99 inline StatusOr<TType>::StatusOr(
const StatusOr &other) : status_(
100 other.status_), value_(other.value_)
103 template<
typename TType>
104 template<
typename TTypeOther>
105 inline StatusOr<TType>::StatusOr(
const StatusOr<TTypeOther> &other,
106 typename std::enable_if<std::is_convertible<TTypeOther, TType>::value>::type *)
107 : status_(other.status_),
108 value_(other.status_.ok() ? other.value_
112 template<
typename TType>
113 template<
typename TTypeOther>
114 inline StatusOr<TType>::StatusOr(
const StatusOr<TTypeOther> &other,
115 typename std::enable_if<!std::is_convertible<TTypeOther, TType>::value>::type *)
117 static_assert(std::is_convertible<TTypeOther, TType>::value,
118 "StatusOr value must be convertible.");
121 template<
typename TType>
122 inline StatusOr<TType> &
123 StatusOr<TType>::operator=(
const StatusOr &other)
125 status_ = other.status_;
126 value_ = other.value_;
131 template<
typename TType>
132 inline const Status &StatusOr<TType>::status()
const
135 template<
typename TType>
136 inline bool StatusOr<TType>::ok()
const
137 {
return status_.ok(); }
139 template<
typename TType>
140 StatusOr<TType>::operator bool()
const
143 template<
typename TType>
144 const TType &StatusOr<TType>::value()
const
155 #endif //LODESTAR_STATUSOR_HPP