【发布时间】:2015-02-16 15:17:40
【问题描述】:
有人知道如何检查任意方法是否为 const 吗?
喜欢:
static_assert(is_const<vector<int>::size>::value, "size is not const");
static_assert(!is_const<vector<int>::push_back>::value, "push_back is const");
好问题 T.C :) 我发现该方法有一个特定的重载,如果我发现的方法是非常量的,我只想设置一个修改标志。
这是我的模板和maro:
#define FRET_DECL_TYPE(Function) \
template<typename T_, typename ... Args_> \
struct f_ret##Function { typedef decltype(std::declval<T_&>().Function(std::declval<Args_&&>()...)) type; };
#define RPROP_PROXY_METHOD(Function) \
FRET_DECL_TYPE(Function) \
template<typename ... Args> \
typename f_ret##Function<T, Args...>::type \
Function(Args&& ... args) const { return this->GetReference().Function(static_cast<Args&&>(args)...); }; \
template<typename ... Args> \
typename f_ret##Function<T, Args...>::type \
Function(Args&& ... args) { this->SetModified(true); return this->GetReference().Function(static_cast<Args&&>(args)...); }; \
【问题讨论】:
-
is_const应该返回vector<int>::begin什么? -
也许这可以帮助你:stackoverflow.com/questions/257288/…
标签: c++ function templates constants typetraits