5 #ifndef ICE_UTIL_OPTIONAL_H
6 #define ICE_UTIL_OPTIONAL_H
8 #ifndef ICE_CPP11_MAPPING
12 namespace IceUtilInternal
25 const IceUtilInternal::NoneType
None = {};
33 typedef T element_type;
45 Optional(IceUtilInternal::NoneType) : _isSet(false)
62 Optional(Y p) : _value(p), _isSet(true)
71 Optional(
const Optional<Y>& r) : _value(r._value), _isSet(r._isSet)
82 Optional& operator=(IceUtilInternal::NoneType)
106 Optional& operator=(
const Optional<Y>& r)
129 const T& value()
const
171 const T* operator->()
const
191 const T& operator*()
const
210 operator bool()
const
219 bool operator!()
const
230 std::swap(_isSet, other._isSet);
231 std::swap(_value, other._value);
243 void checkIsSet()
const
247 throwOptionalNotSetException(__FILE__, __LINE__);
251 void throwOptionalNotSetException(
const char *,
int)
const;
262 template<
class T>
inline Optional<T>
263 makeOptional(
const T& v)
265 return Optional<T>(v);
269 template<
typename T>
inline void
270 Optional<T>::throwOptionalNotSetException(
const char* file,
int line)
const
272 throw OptionalNotSetException(file, line);
276 template<
typename T,
typename U>
277 inline bool operator==(
const Optional<T>& lhs,
const Optional<U>& rhs)
289 template<
typename T,
typename U>
290 inline bool operator!=(
const Optional<T>& lhs,
const Optional<U>& rhs)
295 template<
typename T,
typename U>
296 inline bool operator<(
const Optional<T>& lhs,
const Optional<U>& rhs)
308 template<
typename T,
typename U>
309 inline bool operator<=(
const Optional<T>& lhs,
const Optional<U>& rhs)
311 return lhs < rhs || lhs == rhs;
314 template<
typename T,
typename U>
315 inline bool operator>(
const Optional<T>& lhs,
const Optional<U>& rhs)
317 return !(lhs < rhs || lhs == rhs);
320 template<
typename T,
typename U>
321 inline bool operator>=(
const Optional<T>& lhs,
const Optional<U>& rhs)
328 template<
typename T,
typename Y>
329 inline bool operator==(
const Optional<T>& lhs,
const Y& rhs)
341 template<
typename T,
typename Y>
342 inline bool operator!=(
const Optional<T>& lhs,
const Y& rhs)
347 template<
typename T,
typename Y>
348 inline bool operator<(
const Optional<T>& lhs,
const Y& rhs)
360 template<
typename T,
typename Y>
361 inline bool operator<=(
const Optional<T>& lhs,
const Y& rhs)
363 return lhs < rhs || lhs == rhs;
366 template<
typename T,
typename Y>
367 inline bool operator>(
const Optional<T>& lhs,
const Y& rhs)
369 return !(lhs < rhs || lhs == rhs);
372 template<
typename T,
typename Y>
373 inline bool operator>=(
const Optional<T>& lhs,
const Y& rhs)
380 template<
typename T,
typename Y>
381 inline bool operator==(
const Y& lhs,
const Optional<T>& rhs)
393 template<
typename T,
typename Y>
394 inline bool operator!=(
const Y& lhs,
const Optional<T>& rhs)
399 template<
typename T,
typename Y>
400 inline bool operator<(
const Y& lhs,
const Optional<T>& rhs)
412 template<
typename T,
typename Y>
413 inline bool operator<=(
const Y& lhs,
const Optional<T>& rhs)
415 return lhs < rhs || lhs == rhs;
418 template<
typename T,
typename Y>
419 inline bool operator>(
const Y& lhs,
const Optional<T>& rhs)
421 return !(lhs < rhs || lhs == rhs);
424 template<
typename T,
typename Y>
425 inline bool operator>=(
const Y& lhs,
const Optional<T>& rhs)