Types - T_Optional access
Changed so it's relatively similar to the interface of pointers.
This commit is contained in:
parent
82fc8406b3
commit
46fa84d967
5 changed files with 48 additions and 21 deletions
include/ebcl
|
@ -42,11 +42,11 @@ template<
|
|||
constexpr bool operator!( ) const noexcept;
|
||||
explicit constexpr operator Storage( ) const noexcept;
|
||||
|
||||
constexpr bool operator ==( const T_Flags other ) const noexcept;
|
||||
constexpr bool operator !=( const T_Flags other ) const noexcept;
|
||||
constexpr bool operator ==( T_Flags other ) const noexcept;
|
||||
constexpr bool operator !=( T_Flags other ) const noexcept;
|
||||
|
||||
constexpr bool isSet( const T_Flags value ) const noexcept;
|
||||
constexpr bool isClear( const T_Flags value ) const noexcept;
|
||||
constexpr bool isSet( T_Flags value ) const noexcept;
|
||||
constexpr bool isClear( T_Flags value ) const noexcept;
|
||||
};
|
||||
|
||||
|
||||
|
@ -393,13 +393,16 @@ class T_Optional
|
|||
void clear( ) noexcept;
|
||||
|
||||
// Is there a value?
|
||||
constexpr bool present( ) const noexcept;
|
||||
constexpr operator bool( ) const noexcept;
|
||||
constexpr bool operator!( ) const noexcept;
|
||||
// Pointer to value or nullptr if no value
|
||||
constexpr Type const* target( ) const noexcept;
|
||||
constexpr Type* target( ) noexcept;
|
||||
// Reference to value or std::bad_cast if no value
|
||||
operator Type const&( ) const;
|
||||
operator Type& ( );
|
||||
// Access value or std::bad_cast if no value
|
||||
Type const& operator*( ) const;
|
||||
Type& operator*( );
|
||||
Type const* operator->( ) const;
|
||||
Type* operator->( );
|
||||
};
|
||||
|
||||
template< typename Type >
|
||||
|
|
|
@ -103,12 +103,12 @@ inline size_t T_SRDLocation::byte( ) const noexcept
|
|||
|
||||
inline bool T_SRDLocation::isChained( ) const noexcept
|
||||
{
|
||||
return chaining_.present( );
|
||||
return chaining_;
|
||||
}
|
||||
|
||||
inline T_SRDLocationChaining const& T_SRDLocation::chaining( ) const noexcept
|
||||
{
|
||||
return chaining_;
|
||||
return *chaining_;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -864,11 +864,17 @@ inline void T_Optional< T >::clear( ) noexcept
|
|||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename T >
|
||||
inline constexpr bool T_Optional< T >::present( ) const noexcept
|
||||
inline constexpr T_Optional< T >::operator bool( ) const noexcept
|
||||
{
|
||||
return present_;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
inline constexpr bool T_Optional< T >::operator!( ) const noexcept
|
||||
{
|
||||
return !present_;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
inline constexpr T const* T_Optional< T >::target( ) const noexcept
|
||||
{
|
||||
|
@ -882,7 +888,7 @@ inline constexpr T* T_Optional< T >::target( ) noexcept
|
|||
}
|
||||
|
||||
template< typename T >
|
||||
inline T_Optional< T >::operator T const&( ) const
|
||||
inline T const& T_Optional< T >::operator*( ) const
|
||||
{
|
||||
if ( present_ ) {
|
||||
return *target( );
|
||||
|
@ -891,7 +897,7 @@ inline T_Optional< T >::operator T const&( ) const
|
|||
}
|
||||
|
||||
template< typename T >
|
||||
inline T_Optional< T >::operator T& ( )
|
||||
inline T& T_Optional< T >::operator*( )
|
||||
{
|
||||
if ( present_ ) {
|
||||
return *target( );
|
||||
|
@ -899,6 +905,24 @@ inline T_Optional< T >::operator T& ( )
|
|||
throw std::bad_cast( );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
inline T const* T_Optional< T >::operator->( ) const
|
||||
{
|
||||
if ( present_ ) {
|
||||
return target( );
|
||||
}
|
||||
throw std::bad_cast( );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
inline T* T_Optional< T >::operator->( )
|
||||
{
|
||||
if ( present_ ) {
|
||||
return target( );
|
||||
}
|
||||
throw std::bad_cast( );
|
||||
}
|
||||
|
||||
|
||||
/*= T_Union ==================================================================*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue