これは、クラスメンバーメソッドの署名を保持するためのテンプレートです。これにはデフォルトの実装はありませんが、メソッドがCスタイルの可変パラメータを持っているか持っていないか、cv修飾子のすべての組み合わせを持っているか持っていないすべての場合に特化しています。これらのすべてが8つの非常によく似たコードを生成します。 は、誰もがこのテンプレートを縮小するために、いくつかの方法を提案でした:テンプレートコードを最小化するにはどうすればよいですか?
#include <type_traits>
template <typename ... args>
struct params_t
{
// ...
};
template <typename T>
struct mem_fn_t;
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ...)>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ...);
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ...) const>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ...) const;
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ...) volatile>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ...) volatile;
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ...) const volatile>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ...) const volatile;
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ... , ...)>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ... , ...);
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ... , ...) const>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ... , ...) const;
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ... , ...) volatile>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ... , ...) volatile;
typedef typename std::remove_pointer<pfunction>::type function;
};
template <typename class_t, typename ret_val_t, typename ... args>
struct mem_fn_t<ret_val_t (class_t::*)(args ... , ...) const volatile>
{
typedef class_t class_type;
typedef ret_val_t result_type;
typedef params_t<args...> params_type;
typedef result_type (class_type::*pfunction)(args ... , ...) const volatile;
typedef typename std::remove_pointer<pfunction>::type function;
};
ん[この](http://stackoverflow.com/questions/14926482/const-and-non -const-template-specialization)はまったく役に立ちますか? – Matt
多分、私はどのように見ることができません。私はクラス内のcvに関する情報を保存し、それを消去しないことを望みます。 – user2807083