OSDN Git Service

bool_comparable に ADL 対策をした
authorSubaruG <subaru_g@users.sourceforge.jp>
Thu, 28 Jan 2010 18:07:53 +0000 (03:07 +0900)
committerSubaruG <subaru_g@users.sourceforge.jp>
Thu, 28 Jan 2010 18:07:53 +0000 (03:07 +0900)
gintenlib/bool_comparable.hpp

index e975be1..ca3de1c 100644 (file)
 
 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>
@@ -211,6 +216,9 @@ namespace gintenlib
     // 他のテンプレートでも derived は使いたいぜ
     template<typename U> 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_type>( &bool_comparable_helper::bool_value );
+      return reinterpret_cast<bool_type>( &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<Derived>
+  
+ }  // namespace bool_comparable_
+  // gintenlib 名前空間に引き入れる
+  using namespace bool_comparable_;
 
 } // namespace gintenlib