連想コンテナ(4)

dataをポインタではなく実体で受け取る場合,参照渡しのほうがいいのではないか?

また,keyもbool operator()(const Item& i, const KeyType& k)のKeyType&ように常に参照渡しになっている部分があるが,デフォルトのintの場合は値で受け取り,int以外の場合(文字列とか)は参照渡しのほうがいいのではないか?
最初は,

template
struct IsPointer { enum { value = false }; };
template
struct IsPointer { enum { value = true }; };

template< bool flag, typename T, typename U>
struct Select { typedef T Result; };
template
struct Select { typedef T Result; };

typedef typename Select< IsPointer::value, T, T& >::Result DataParamType;

のようにしてみたが,

template
struct TypeTraits { typedef T& ParamType; };
template
struct TypeTraits { typedef T* ParamType; };
template<>
struct TypeTraits { typedef int ParamType; };

typedef typename TypeTraits::ParamType DataParamType;
typedef typename TypeTraits::ParamType KeyParamType;

に変更した.

メンバ関数の引数も void Insert( KeyType key, DataType data) を void Insert( KeyParamType key, DataParamType data) 等に変更する.


Boostのtype-traitsの実装を見ていないので,かなり間抜けなことをしているかも.