Added move only data type

This commit is contained in:
John Wellbelove 2019-01-01 14:03:21 +00:00
parent 96ce602874
commit cae432fc31
3 changed files with 89 additions and 0 deletions

View File

@ -152,4 +152,89 @@ std::ostream& operator << (std::ostream& s, const TestDataNDC<T>& rhs)
return s;
}
//*****************************************************************************
// Movable.
//*****************************************************************************
template <typename T>
class TestDataM : public etl::instance_count<TestDataM<T>>
{
public:
explicit TestDataM(const T& value_)
: value(value_)
, valid(true)
{
}
TestDataM(TestDataM&& other)
: value(other.value)
, valid(true)
{
other.value = T();
other.valid = false;
}
TestDataM& operator =(TestDataM&& other)
{
value = other.value;
valid = true;
other.value = T();
other.valid = false;
}
bool operator < (const TestDataM& other) const
{
return value < other.value;
}
bool operator > (const TestDataM& other) const
{
return other.value < value;
}
bool operator <= (const TestDataM& other) const
{
return !(other.value < value);
}
bool operator >= (const TestDataM& other) const
{
return !(value < other.value);
}
operator bool() const
{
return valid;
}
T value;
bool valid;
private:
TestDataM(const TestDataM& other) = delete;
TestDataM& operator =(const TestDataM& other) = delete;
};
template <typename T>
bool operator == (const TestDataM<T>& lhs, const TestDataM<T>& rhs)
{
return lhs.value == rhs.value;
}
template <typename T>
bool operator != (const TestDataM<T>& lhs, const TestDataM<T>& rhs)
{
return lhs.value != rhs.value;
}
template <typename T>
std::ostream& operator << (std::ostream& s, const TestDataM<T>& rhs)
{
s << rhs.value;
return s;
}
#endif

View File

@ -532,6 +532,7 @@
<ClInclude Include="..\..\include\etl\vector.h" />
<ClInclude Include="..\..\include\etl\visitor.h" />
<ClInclude Include="..\..\include\etl\wstring.h" />
<ClInclude Include="..\data.h" />
<ClInclude Include="..\ecl_user.h" />
<ClInclude Include="..\etl_profile.h" />
<ClInclude Include="..\murmurhash3.h" />

View File

@ -720,6 +720,9 @@
<ClInclude Include="..\..\include\etl\absolute.h">
<Filter>ETL\Maths</Filter>
</ClInclude>
<ClInclude Include="..\data.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp">