mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-29 12:45:40 +08:00
refs #937 Resolved clazy warnings: unnecessary detaching of containers.
This commit is contained in:
@@ -289,24 +289,54 @@ namespace BlackMisc
|
||||
|
||||
/*!
|
||||
* Returns a CRange constructed from the begin and end iterators of the given container.
|
||||
*
|
||||
* The returned CRange may or may not be const, depending on the constness of the container.
|
||||
*/
|
||||
//! @{
|
||||
template <class T>
|
||||
auto makeRange(T &&container) -> CRange<decltype(container.begin())>
|
||||
auto makeRange(T &container) -> CRange<decltype(container.begin())>
|
||||
{
|
||||
return { container.begin(), container.end() };
|
||||
}
|
||||
template <class T>
|
||||
auto makeRange(const T &container) -> CRange<decltype(container.begin())>
|
||||
{
|
||||
return { container.begin(), container.end() };
|
||||
}
|
||||
//! @}
|
||||
|
||||
/*!
|
||||
* Returns a const CRange constructed from the cbegin and cend iterators of the given container.
|
||||
*/
|
||||
template <class T>
|
||||
auto makeConstRange(T &&container) -> CRange<decltype(container.cbegin())>
|
||||
auto makeConstRange(const T &container) -> CRange<decltype(container.cbegin())>
|
||||
{
|
||||
return { container.cbegin(), container.cend() };
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns a const CRange for iterating over the keys of an associative container.
|
||||
*
|
||||
* This is more efficient than the keys() method of the container, as it doesn't allocate memory.
|
||||
*/
|
||||
template <class T>
|
||||
auto makeKeysRange(const T &container)
|
||||
{
|
||||
return makeRange(Iterators::makeKeyIterator(container.cbegin()), container.cend());
|
||||
}
|
||||
|
||||
/*!
|
||||
* Keys range for a non-const lvalue would be unsafe due to iterator invalidation on detach().
|
||||
*
|
||||
* \see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
|
||||
*/
|
||||
template <class T>
|
||||
void makeKeysRange(T &container) = delete;
|
||||
|
||||
/*!
|
||||
* Keys range for a temporary would be unsafe.
|
||||
*/
|
||||
template <class T>
|
||||
void makeKeysRange(const T &&container) = delete;
|
||||
|
||||
/*
|
||||
* Member functions of CRangeBase template defined out of line, because they depend on CRange etc.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user