namespace gintenlib
{
+ namespace bool_comparable_ // ADL 回避
+ {
// ヘルパ構造体
- struct bool_comparable_helper
+ namespace detail_
{
- // operator bool_type() の戻り値として使われる値
- void bool_value() const {}
+ struct bool_comparable_helper
+ {
+ // operator bool_type() の戻り値として使われる値
+ void bool_value() const {}
+
+ private:
+ // コンパイルエラーを起こすための private 関数
+ bool this_type_does_not_support_comparisons_();
- private:
- // コンパイルエラーを起こすための private 関数
- bool this_type_does_not_support_comparisons_();
-
- };
+ };
+ }
// 本体
template<typename Derived>
// 他のテンプレートでも derived は使いたいぜ
template<typename U> friend class bool_comparable;
+ // ヘルパ構造体名を適当に短縮
+ typedef detail_::bool_comparable_helper helper;
+
public:
// 本題
operator bool_type() const
static bool_type bool_value_()
{
// 関数を無駄に作らせない工夫。どうせ bool_type の値は使わないし
- return reinterpret_cast<bool_type>( &bool_comparable_helper::bool_value );
+ return reinterpret_cast<bool_type>( &helper::bool_value );
}
// テスト関数
// 等値比較
friend bool operator==( const bool_comparable& lhs, const bool_comparable& rhs )
{
- return bool_comparable_helper().this_type_does_not_support_comparisons_();
+ return helper().this_type_does_not_support_comparisons_();
}
// 不等値比較
friend bool operator!=( const bool_comparable& lhs, const bool_comparable& rhs )
{
- return bool_comparable_helper().this_type_does_not_support_comparisons_();
+ return helper().this_type_does_not_support_comparisons_();
}
protected:
~bool_comparable() {}
}; // class bool_comparable<Derived>
+
+ } // namespace bool_comparable_
+
+ // gintenlib 名前空間に引き入れる
+ using namespace bool_comparable_;
} // namespace gintenlib