diff options
author | Bernard Normier <bernard@zeroc.com> | 2017-03-08 18:07:20 -0500 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2017-03-08 18:07:20 -0500 |
commit | fa2bed313b7b84b80606ef80dee0b13f2401f462 (patch) | |
tree | 1624b1d11e482ab0d1cdb8b0b3e08349be9b0c95 | |
parent | CSharp implementation failures (diff) | |
download | ice-fa2bed313b7b84b80606ef80dee0b13f2401f462.tar.bz2 ice-fa2bed313b7b84b80606ef80dee0b13f2401f462.tar.xz ice-fa2bed313b7b84b80606ef80dee0b13f2401f462.zip |
Refreshed Ice::optional
-rw-r--r-- | cpp/include/Ice/Optional.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/cpp/include/Ice/Optional.h b/cpp/include/Ice/Optional.h index a1305dd93be..fa854400e70 100644 --- a/cpp/include/Ice/Optional.h +++ b/cpp/include/Ice/Optional.h @@ -8,17 +8,17 @@ // ********************************************************************** // -// Ice::optional is a placeholder std::optional: +// Ice::optional is a placeholder for std::optional: // http://en.cppreference.com/w/cpp/utility/optional/optional // // This implementation is a slighly modified version of Optional.hpp, // published at https://github.com/akrzemi1/Optional -// commit 3922965396fc455c6b1770374b9b4111799588a9 +// commit 25713110f55813b2c5619ec1230edf8d3b00bdde -// Copyright (C) 2011 - 2012 Andrzej Krzemienski. +// Copyright (C) 2011-2016 Andrzej Krzemienski // -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at // http://www.boost.org/LICENSE_1_0.txt) // // The idea and interface is based on Boost.Optional library @@ -365,8 +365,8 @@ struct constexpr_optional_base template <class T> using OptionalBase = typename std::conditional< - is_trivially_destructible<T>::value, - constexpr_optional_base<typename std::remove_const<T>::type>, + is_trivially_destructible<T>::value, // if possible + constexpr_optional_base<typename std::remove_const<T>::type>, // use base with trivial destructor optional_base<typename std::remove_const<T>::type> >::type; @@ -521,6 +521,7 @@ public: // 20.5.4.5, Observers explicit constexpr operator bool() const noexcept { return initialized(); } + constexpr bool has_value() const noexcept { return initialized(); } constexpr T const* operator ->() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr()); @@ -622,6 +623,8 @@ public: # endif + // 20.6.3.6, modifiers + void reset() noexcept { clear(); } }; @@ -717,11 +720,18 @@ public: return ref != nullptr; } + constexpr bool has_value() const noexcept { + return ref != nullptr; + } + template <class V> constexpr typename decay<T>::type value_or(V&& v) const { return *this ? **this : detail_::convert<typename decay<T>::type>(constexpr_forward<V>(v)); } + + // x.x.x.x, modifiers + void reset() noexcept { ref = nullptr; } }; |