mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-26 20:38:45 +08:00
Changed unique() to underlying_type()
Added underlying_type() to etl::not_null<T*>
This commit is contained in:
parent
08ed69bac7
commit
94f7d9956d
@ -87,12 +87,13 @@ namespace etl
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef pointer underlying_type;
|
||||
|
||||
//*********************************
|
||||
/// Constructs a not_null from a pointer.
|
||||
/// Asserts if the pointer is null.
|
||||
//*********************************
|
||||
explicit not_null(pointer ptr_)
|
||||
explicit not_null(underlying_type ptr_)
|
||||
: ptr(ptr_)
|
||||
{
|
||||
ETL_ASSERT(ptr_ != ETL_NULLPTR, ETL_ERROR(not_null_contains_null));
|
||||
@ -120,7 +121,7 @@ namespace etl
|
||||
/// Assignment from a pointer.
|
||||
/// Asserts if the pointer is null.
|
||||
//*********************************
|
||||
not_null& operator =(pointer rhs)
|
||||
not_null& operator =(underlying_type rhs)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(rhs != ETL_NULLPTR, ETL_ERROR(not_null_contains_null), *this);
|
||||
|
||||
@ -161,6 +162,22 @@ namespace etl
|
||||
return ptr;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// Gets a reference to the underlying pointer.
|
||||
//*********************************
|
||||
underlying_type& underlying()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// Gets a const_reference to the underlying pointer.
|
||||
//*********************************
|
||||
const underlying_type& underlying() const
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// The underlying pointer.
|
||||
@ -182,14 +199,14 @@ namespace etl
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
|
||||
typedef etl::unique_ptr<T, TDeleter> unique_ptr_type;
|
||||
typedef etl::unique_ptr<T, TDeleter> underlying_type;;
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*********************************
|
||||
/// Constructs a not_null from a unique_ptr.
|
||||
/// Asserts if the unique_ptr is null.
|
||||
//*********************************
|
||||
explicit not_null(unique_ptr_type&& u_ptr_)
|
||||
explicit not_null(underlying_type&& u_ptr_)
|
||||
: u_ptr(etl::move(u_ptr_))
|
||||
{
|
||||
ETL_ASSERT(u_ptr.get() != ETL_NULLPTR, ETL_ERROR(not_null_contains_null));
|
||||
@ -198,7 +215,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// Constructs a not_null from a unique_ptr.
|
||||
//*********************************
|
||||
not_null(etl::not_null<unique_ptr_type>&& other)
|
||||
not_null(etl::not_null<underlying_type>&& other)
|
||||
: u_ptr(etl::move(other.u_ptr))
|
||||
{
|
||||
}
|
||||
@ -207,7 +224,7 @@ namespace etl
|
||||
/// Assign from a unique_ptr.
|
||||
/// Asserts if the unique_ptr is null.
|
||||
//*********************************
|
||||
not_null& operator =(unique_ptr_type&& rhs)
|
||||
not_null& operator =(underlying_type&& rhs)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(rhs.get() != ETL_NULLPTR, ETL_ERROR(not_null_contains_null), *this);
|
||||
|
||||
@ -219,7 +236,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// Assign from a not_null.
|
||||
//*********************************
|
||||
not_null& operator =(etl::not_null<unique_ptr_type>&& rhs)
|
||||
not_null& operator =(etl::not_null<underlying_type>&& rhs)
|
||||
{
|
||||
u_ptr = etl::move(rhs.u_ptr);
|
||||
|
||||
@ -260,17 +277,17 @@ namespace etl
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// Gets the underlying unique_ptr.
|
||||
/// Gets a reference to the underlying unique_ptr.
|
||||
//*********************************
|
||||
unique_ptr_type& unique()
|
||||
underlying_type& underlying()
|
||||
{
|
||||
return u_ptr;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// Gets the underlying unique_ptr.
|
||||
/// Gets a const_reference to the underlying unique_ptr.
|
||||
//*********************************
|
||||
const unique_ptr_type& unique() const
|
||||
const underlying_type& underlying() const
|
||||
{
|
||||
return u_ptr;
|
||||
}
|
||||
@ -278,7 +295,7 @@ namespace etl
|
||||
private:
|
||||
|
||||
/// The underlying unique_ptr.
|
||||
unique_ptr_type u_ptr;
|
||||
underlying_type u_ptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -79,6 +79,40 @@ namespace
|
||||
CHECK_EQUAL(456, *nn2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_underlying)
|
||||
{
|
||||
int value1 = 123;
|
||||
etl::not_null<int*> nn1(&value1);
|
||||
|
||||
int* p = nn1.underlying();
|
||||
|
||||
CHECK_EQUAL(123, *p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_underlying_const)
|
||||
{
|
||||
int value1 = 123;
|
||||
const etl::not_null<int*> nn1(&value1);
|
||||
|
||||
const int* p = nn1.underlying();
|
||||
|
||||
CHECK_EQUAL(123, *p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_unique_const)
|
||||
{
|
||||
using up_t = etl::unique_ptr<int>;
|
||||
up_t up1(new int{ 123 });
|
||||
const etl::not_null<up_t> nn(etl::move(up1));
|
||||
|
||||
const up_t& up2 = nn.underlying();
|
||||
|
||||
CHECK_EQUAL(123, *up2.get());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_implicit_conversion)
|
||||
{
|
||||
|
||||
@ -55,25 +55,25 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_unique)
|
||||
TEST(test_underlying)
|
||||
{
|
||||
using up_t = etl::unique_ptr<int>;
|
||||
up_t up1(new int{ 123 });
|
||||
etl::not_null<up_t> nn(etl::move(up1));
|
||||
|
||||
up_t up2 = etl::move(nn.unique());
|
||||
up_t up2 = etl::move(nn.underlying());
|
||||
|
||||
CHECK_EQUAL(123, *up2.get());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_unique_const)
|
||||
TEST(test_underlying_const)
|
||||
{
|
||||
using up_t = etl::unique_ptr<int>;
|
||||
up_t up1(new int{ 123 });
|
||||
const etl::not_null<up_t> nn(etl::move(up1));
|
||||
|
||||
const up_t& up2 = nn.unique();
|
||||
const up_t& up2 = etl::move(nn.underlying());
|
||||
|
||||
CHECK_EQUAL(123, *up2.get());
|
||||
}
|
||||
|
||||
@ -3362,6 +3362,7 @@
|
||||
<ClInclude Include="..\..\include\etl\math.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_broker.h" />
|
||||
<ClInclude Include="..\..\include\etl\monostate.h" />
|
||||
<ClInclude Include="..\..\include\etl\not_null.h" />
|
||||
<ClInclude Include="..\..\include\etl\poly_span.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\bitset_legacy.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\bitset_new.h" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user