У кого-то есть идея проверить, является ли произвольный метод const?Проверить, является ли метод 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 :) Я находя определенную перегрузку метода, и я хочу только установить модифицированный флаг, если метод я нашел это неконстантная.
Вот мои шаблоны и maroes:
#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 :: begin'? –
Возможно, это может вам помочь: http: //stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence – swang