Skip to content

Commit

Permalink
Containers: provide interface for converting Optional to something else.
Browse files Browse the repository at this point in the history
Will be used by Magnum to provide backwards compatibility with
(previously bundled) std::optional. I hated myself for bundling
std::optional, now I will hate myself for doing this.
  • Loading branch information
mosra committed Jan 8, 2018
1 parent d366bab commit 4b77cff
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Corrade/Containers/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

namespace Corrade { namespace Containers {

#ifdef CORRADE_BUILD_DEPRECATED
namespace Implementation { template<class, class> class OptionalConverter; }
#endif

/**
@brief Null optional initialization tag type
Expand Down Expand Up @@ -254,6 +258,17 @@ template<class T> class Optional {
*/
template<class ...Args> T& emplace(Args&&... args);

#if defined(CORRADE_BUILD_DEPRECATED) && !defined(CORRADE_GCC47_COMPATIBILITY)
/* Used by Magnum to provide backwards compatibility with (previously
bundled) std::optional. I hate myself for this. */
template<class U, class V = decltype(Implementation::OptionalConverter<T, U>::to(std::declval<Optional<T>>()))> operator U() const & {
return Implementation::OptionalConverter<T, U>::to(*this);
}
template<class U, class V = decltype(Implementation::OptionalConverter<T, U>::to(std::declval<Optional<T>>()))> operator U() && {
return Implementation::OptionalConverter<T, U>::to(std::move(*this));
}
#endif

private:
union Storage {
constexpr Storage() noexcept: _{} {}
Expand Down

0 comments on commit 4b77cff

Please sign in to comment.