mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 03:48:02 +08:00
cmAlgorithms: Make cmRange advance/retreat safe for rvalues
In rvalue context these functions have to return cmRange by copy instead of reference to temporary object It allows to use ranged-for over cmMakeRange(xxx).advance(yyy)
This commit is contained in:
@@ -172,18 +172,30 @@ struct cmRange
|
|||||||
const_iterator end() const { return End; }
|
const_iterator end() const { return End; }
|
||||||
bool empty() const { return std::distance(Begin, End) == 0; }
|
bool empty() const { return std::distance(Begin, End) == 0; }
|
||||||
difference_type size() const { return std::distance(Begin, End); }
|
difference_type size() const { return std::distance(Begin, End); }
|
||||||
cmRange& advance(KWIML_INT_intptr_t amount)
|
|
||||||
|
cmRange& advance(KWIML_INT_intptr_t amount) &
|
||||||
{
|
{
|
||||||
std::advance(Begin, amount);
|
std::advance(this->Begin, amount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
cmRange advance(KWIML_INT_intptr_t amount) &&
|
||||||
|
{
|
||||||
|
std::advance(this->Begin, amount);
|
||||||
|
return std::move(*this);
|
||||||
|
}
|
||||||
|
|
||||||
cmRange& retreat(KWIML_INT_intptr_t amount)
|
cmRange& retreat(KWIML_INT_intptr_t amount) &
|
||||||
{
|
{
|
||||||
std::advance(End, -amount);
|
std::advance(End, -amount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmRange retreat(KWIML_INT_intptr_t amount) &&
|
||||||
|
{
|
||||||
|
std::advance(End, -amount);
|
||||||
|
return std::move(*this);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const_iterator Begin;
|
const_iterator Begin;
|
||||||
const_iterator End;
|
const_iterator End;
|
||||||
|
Reference in New Issue
Block a user