diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-06-29 23:23:43 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-08-01 15:19:45 -0700 |
commit | 3b98f3439e33b15bba2036c402f9925340fdb2b9 (patch) | |
tree | f6a59330bb747d9cc64f5f83d06e7f76dc01d540 /src/common/utils2.hpp | |
parent | 8d1480c1be7c9741876d89008277a2b3629a4d01 (diff) | |
download | tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.tar.gz tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.tar.bz2 tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.tar.xz tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.zip |
Poison std::string and use the various string classes
Diffstat (limited to 'src/common/utils2.hpp')
-rw-r--r-- | src/common/utils2.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp index d7d6f8a..119cc13 100644 --- a/src/common/utils2.hpp +++ b/src/common/utils2.hpp @@ -248,4 +248,33 @@ typename std::enable_if<is_array_of_unknown_bound<T>::value, std::unique_ptr<T, return std::unique_ptr<E[], D>(new E[sz]()); } +template<class T> +const T& const_(T& t) +{ + return t; +} + +template<class T, class U> +T no_cast(U&& u) +{ + typedef typename std::remove_reference<T>::type Ti; + typedef typename std::remove_reference<U>::type Ui; + typedef typename std::remove_cv<Ti>::type Tb; + typedef typename std::remove_cv<Ui>::type Ub; + static_assert(std::is_same<Tb, Ub>::value, "not no cast"); + return std::forward<U>(u); +} + +template<class T, class U> +T base_cast(U&& u) +{ + static_assert(std::is_reference<T>::value, "must base cast with references"); + typedef typename std::remove_reference<T>::type Ti; + typedef typename std::remove_reference<U>::type Ui; + typedef typename std::remove_cv<Ti>::type Tb; + typedef typename std::remove_cv<Ui>::type Ub; + static_assert(std::is_base_of<Tb, Ub>::value, "not base cast"); + return std::forward<U>(u); +} + #endif // UTILS2_HPP |