diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-27 17:56:06 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-27 18:59:57 -0700 |
| commit | 75e8752cb90eb8bc7717518d9d6a5c68f27f2b0f (patch) | |
| tree | b3a8c01beebba2b7e5524363b59bfc088aab83a2 /toolsrc/include/vcpkg_optional.h | |
| parent | db2bc7ed80cd85935bcf80a02a06c796d01197b7 (diff) | |
| download | vcpkg-75e8752cb90eb8bc7717518d9d6a5c68f27f2b0f.tar.gz vcpkg-75e8752cb90eb8bc7717518d9d6a5c68f27f2b0f.zip | |
Run clang-format over the headers. Remove stray Version.h/cpp. Fix location of VersionT.cpp
Diffstat (limited to 'toolsrc/include/vcpkg_optional.h')
| -rw-r--r-- | toolsrc/include/vcpkg_optional.h | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/toolsrc/include/vcpkg_optional.h b/toolsrc/include/vcpkg_optional.h index 380e54f1c..3b94d5a5d 100644 --- a/toolsrc/include/vcpkg_optional.h +++ b/toolsrc/include/vcpkg_optional.h @@ -10,18 +10,18 @@ namespace vcpkg const static constexpr NullOpt nullopt{ 0 }; - template <class T> + template<class T> class Optional { public: - constexpr Optional() : m_is_present(false), m_t() { } + constexpr Optional() : m_is_present(false), m_t() {} // Constructors are intentionally implicit - constexpr Optional(NullOpt) : m_is_present(false), m_t() { } + constexpr Optional(NullOpt) : m_is_present(false), m_t() {} - Optional(const T& t) : m_is_present(true), m_t(t) { } + Optional(const T& t) : m_is_present(true), m_t(t) {} - Optional(T&& t) : m_is_present(true), m_t(std::move(t)) { } + Optional(T&& t) : m_is_present(true), m_t(std::move(t)) {} T&& value_or_exit(const LineInfo& line_info) && { @@ -35,37 +35,25 @@ namespace vcpkg return this->m_t; } - constexpr explicit operator bool() const - { - return this->m_is_present; - } + constexpr explicit operator bool() const { return this->m_is_present; } - constexpr bool has_value() const - { - return m_is_present; - } + constexpr bool has_value() const { return m_is_present; } - template <class U> + template<class U> T value_or(U&& default_value) const & { return bool(*this) ? this->m_t : static_cast<T>(std::forward<U>(default_value)); } - template <class U> + template<class U> T value_or(U&& default_value) && { return bool(*this) ? std::move(this->m_t) : static_cast<T>(std::forward<U>(default_value)); } - const T* get() const - { - return bool(*this) ? &this->m_t : nullptr; - } + const T* get() const { return bool(*this) ? &this->m_t : nullptr; } - T* get() - { - return bool(*this) ? &this->m_t : nullptr; - } + T* get() { return bool(*this) ? &this->m_t : nullptr; } private: void exit_if_null(const LineInfo& line_info) const |
