refs #583 as_const

This commit is contained in:
Mathew Sutcliffe
2016-02-02 18:01:36 +00:00
parent d6b9fe6f95
commit f9ee637a1e

View File

@@ -38,6 +38,18 @@ namespace BlackMisc
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
* to gain some useful algorithms as member functions.