互換性のないtypedef
ようは下のような事がしたかったんです。
typedef int foo; typedef int hoge; foo f = 10; // ok hoge h = 20; // ok f = h; // 型が違うので error にしたい
どこかで見たような気がしたけど、探したのがなかったので作った。
template<
typename key_t,
typename value_t = unsigned int
>
struct only_value_t{
only_value_t()
: value(0){}
only_value_t(value_t rhs)
: value(rhs){}
only_value_t(const only_value_t& rhs)
: value(rhs.value){}
const only_value_t& operator =(const only_value_t& rhs){
value = rhs.value;
return *this;
}
operator value_t(){
return value;
}
value_t get(){
return value;
}
private:
value_t value;
};
typedef only_value_t foo;
typedef only_value_t hoge;
foo f = 10; // ok
hoge h = 20; // ok
f = h; // error
んーなんか難しく考えすぎかなー。
もっと楽な(というか手っ取り早い)方法がありそう…。