Commit 0316219f authored by Eike Ziller's avatar Eike Ziller
Browse files

asConst: Simplify with C++11/14 and fix for rvalue refs

add_const is available since C++11, add_const_t since C++14
Use universal reference && to enable uses like

for (const auto item : Utils::asConst(foo->items())) ...

Change-Id: I17ee19dae22a306ccf92035f43e60e91b32dffd7
Reviewed-by: default avatarhjk <>
parent 6621f559
......@@ -25,12 +25,12 @@
#pragma once
namespace Utils {
#include <type_traits>
template<class T> struct ConstAdder { typedef const T type; };
namespace Utils {
template <class T>
constexpr typename ConstAdder<T>::type &asConst(T &t) noexcept
constexpr std::add_const_t<T> &asConst(T &&t) noexcept
return t;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment