Last active
August 29, 2015 13:56
-
-
Save abergmeier/9135888 to your computer and use it in GitHub Desktop.
Extended equality operator for std::optional.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: Probably necessary to wrap U in decay. | |
template< class T, class U > | |
constexpr typename std::enable_if<!std::is_base_of<std::optional<T>, std::optional<U>>::value, bool>::type | |
operator==( const std::optional<T>& opt, U&& value ) { | |
return opt == static_cast<const U&>( value ); | |
} | |
template< class T, class U > | |
constexpr typename std::enable_if<!std::is_base_of<std::optional<T>, std::optional<U>>::value, bool>::type | |
operator==( U&& value, const std::optional<T>& opt ) { | |
return static_cast<const U&>( value ) == opt; | |
} | |
template< class T, class U > | |
constexpr typename std::enable_if<!std::is_base_of<std::optional<T>, std::optional<U>>::value, bool>::type | |
operator!=( const std::optional<T>& opt, U&& value ) { | |
return !( opt == value ); | |
} | |
template< class T, class U > | |
constexpr typename std::enable_if<!std::is_base_of<std::optional<T>, std::optional<U>>::value, bool>::type | |
operator!=( U&& value, const std::optional<T>& opt ) { | |
return !( opt == value ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment