mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Added move only data type
This commit is contained in:
parent
96ce602874
commit
cae432fc31
85
test/data.h
85
test/data.h
@ -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
|
||||
|
||||
@ -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" />
|
||||
|
||||
@ -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">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user