mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
refs #583 as_const
This commit is contained in:
@@ -38,6 +38,18 @@ namespace BlackMisc
|
|||||||
|
|
||||||
template <class> class CRange;
|
template <class> class CRange;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Own implementation of C++17 std::as_const. Adds const to any lvalue.
|
||||||
|
* Useful with non-mutating range-for loops to avoid unnecessary detachment of Qt implicitly shared containers.
|
||||||
|
* Does not allow rvalues, as that could easily lead to undefined behaviour.
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
template <class T>
|
||||||
|
Q_CONSTEXPR typename std::add_const<T>::type &as_const(T &v) Q_DECL_NOEXCEPT { return v; }
|
||||||
|
template <class T>
|
||||||
|
void as_const(const T &&) = delete;
|
||||||
|
//! @}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Any container class with begin and end iterators can inherit from this CRTP class
|
* Any container class with begin and end iterators can inherit from this CRTP class
|
||||||
* to gain some useful algorithms as member functions.
|
* to gain some useful algorithms as member functions.
|
||||||
|
|||||||
Reference in New Issue
Block a user