From 5f62cb1633e5a5ec284395c1052c874b755baff8 Mon Sep 17 00:00:00 2001 From: SubaruG Date: Fri, 29 Jan 2010 03:07:53 +0900 Subject: [PATCH] =?utf8?q?bool=5Fcomparable=20=E3=81=AB=20ADL=20=E5=AF=BE?= =?utf8?q?=E7=AD=96=E3=82=92=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- gintenlib/bool_comparable.hpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/gintenlib/bool_comparable.hpp b/gintenlib/bool_comparable.hpp index e975be1..ca3de1c 100644 --- a/gintenlib/bool_comparable.hpp +++ b/gintenlib/bool_comparable.hpp @@ -185,17 +185,22 @@ 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 @@ -211,6 +216,9 @@ namespace gintenlib // 他のテンプレートでも derived は使いたいぜ template friend class bool_comparable; + // ヘルパ構造体名を適当に短縮 + typedef detail_::bool_comparable_helper helper; + public: // 本題 operator bool_type() const @@ -281,7 +289,7 @@ namespace gintenlib static bool_type bool_value_() { // 関数を無駄に作らせない工夫。どうせ bool_type の値は使わないし - return reinterpret_cast( &bool_comparable_helper::bool_value ); + return reinterpret_cast( &helper::bool_value ); } // テスト関数 @@ -309,12 +317,12 @@ namespace gintenlib // 等値比較 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: @@ -323,6 +331,11 @@ namespace gintenlib ~bool_comparable() {} }; // class bool_comparable + + } // namespace bool_comparable_ + + // gintenlib 名前空間に引き入れる + using namespace bool_comparable_; } // namespace gintenlib -- 2.11.0