summaryrefslogtreecommitdiffstats
path: root/Source/cmAlgorithms.h
diff options
context:
space:
mode:
authorArtur Ryt <artur.ryt@gmail.com>2019-02-07 21:28:03 (GMT)
committerArtur Ryt <artur.ryt@gmail.com>2019-02-07 21:38:12 (GMT)
commit15bdbec0176e3aa620bb5bda3631819c5ca18eaf (patch)
treea681f34ca76d70956619b7921a0e2a37e5aa56e9 /Source/cmAlgorithms.h
parent41802ef35d58ef9d8761388abeee202503f11642 (diff)
downloadCMake-15bdbec0176e3aa620bb5bda3631819c5ca18eaf.zip
CMake-15bdbec0176e3aa620bb5bda3631819c5ca18eaf.tar.gz
CMake-15bdbec0176e3aa620bb5bda3631819c5ca18eaf.tar.bz2
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)
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r--Source/cmAlgorithms.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 9e3efd3..30328c6 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -172,18 +172,30 @@ struct cmRange
const_iterator end() const { return End; }
bool empty() const { return std::distance(Begin, End) == 0; }
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;
}
+ 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);
return *this;
}
+ cmRange retreat(KWIML_INT_intptr_t amount) &&
+ {
+ std::advance(End, -amount);
+ return std::move(*this);
+ }
+
private:
const_iterator Begin;
const_iterator End;