Utilities
Utilities header only library
StrongOptionalType.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_STRONG_OPTIONAL_TYPE_H
7 #define UTILS_STRONG_OPTIONAL_TYPE_H
8 
9 #include <optional>
10 
11 #include <Utils/StrongType.h>
12 
13 namespace utils
14 {
21  template <typename ValueType, typename PhantomType>
23  : public utils::StrongType<std::optional<ValueType>, PhantomType>
24  {
25  using OptionalValueType = std::optional<ValueType>;
26 
27  public:
29 
30  StrongOptionalType<ValueType, PhantomType> &operator= (const OptionalValueType &value)
31  {
32  this->value_ = value;
33  return *this;
34  }
35 
37  bool HasValue() const { return this->value_.has_value(); }
39  const ValueType &Value() const { return this->value_.value(); }
40  };
41 }
42 
43 #endif /* !UTILS_STRONG_OPTIONAL_TYPE_H */
Template class implementation of a Named Strong Type.
Definition: StrongType.h:28
std::optional specialization of the Strong type pattern.
Definition: StrongOptionalType.h:22
std::optional< ValueType > value_
The actual underlying value.
Definition: StrongType.h:63
General namespace for utilities.
Definition: BulletConversions.h:9
bool HasValue() const
Proxy function to access the underlying optional&#39;s has_value() function.
Definition: StrongOptionalType.h:37
const ValueType & Value() const
Proxy function to access the underlying optional&#39;s value() function.
Definition: StrongOptionalType.h:39