Created
May 18, 2017 17:30
-
-
Save BlueSolei/bca26a8590265492e2f2760d3cefcf83 to your computer and use it in GitHub Desktop.
LikeConstVersion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
template <typename T> | |
struct NonConst | |
{ | |
typedef T type; | |
}; | |
template <typename T> | |
struct NonConst<T const> | |
{ | |
typedef T type; | |
}; // by value | |
template <typename T> | |
struct NonConst<T const&> | |
{ | |
typedef T& type; | |
}; // by reference | |
template <typename T> | |
struct NonConst<T const*> | |
{ | |
typedef T* type; | |
}; // by pointer | |
template <typename T> | |
struct NonConst<T const&&> | |
{ | |
typedef T&& type; | |
}; // by rvalue-reference | |
template <typename TConstReturn, class TObj, typename... TArgs> | |
typename NonConst<TConstReturn>::type | |
LikeConstVersion(TObj const* obj, TConstReturn (TObj::*memFun)(TArgs...) const, TArgs&&... args) | |
{ | |
return const_cast<typename NonConst<TConstReturn>::type>((obj->*memFun)(std::forward<TArgs>(args)...)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment