OSDN Git Service

bool_comparable を最適化 master
authorSubaruG <gintensubaru@gmail.com>
Sun, 14 Nov 2010 14:32:27 +0000 (23:32 +0900)
committerSubaruG <gintensubaru@gmail.com>
Sun, 14 Nov 2010 14:32:27 +0000 (23:32 +0900)
もうちょっと何とかなりそうだけど、今回はこれだけ。
ゆくゆくは C++0x の explicit operator bool に対応させたい。

gintenlib/bool_comparable.hpp

index a9b375c..399c8cd 100644 (file)
@@ -24,7 +24,6 @@
     
      protected:
       bool_comparable() {}
-      ~bool_comparable() {}
     
     };  // class bool_comparable<Derived>
     
   #include <boost/type_traits/is_same.hpp>
 #endif
 
-#include "cast.hpp" // for gintenlib::cast
-
 namespace gintenlib
 {
   // ヘルパ構造体
@@ -211,10 +208,6 @@ namespace gintenlib
     
     // 派生したクラスを得る関数
     const Derived& derived() const { return *static_cast<const Derived*>(this); }
-          Derived& derived()       { return *static_cast<      Derived*>(this); }
-    
-    // 他のテンプレートでも derived は使いたいぜ
-    template<typename U> friend class bool_comparable;
     
     // ヘルパ構造体名を適当に短縮
     typedef ::gintenlib::detail_::bool_comparable_helper helper;
@@ -239,25 +232,25 @@ namespace gintenlib
     friend typename enable_if<boost::is_same<U, bool>, bool>::type
       operator==( const Derived& lhs, U rhs )
     {
-      return cast<bool>(lhs) == rhs;
+      return bool(lhs) == rhs;
     }
     template<typename U>
     friend typename enable_if<boost::is_same<U, bool>, bool>::type
       operator==( U lhs, const Derived& rhs )
     {
-      return lhs == cast<bool>(rhs);
+      return lhs == bool(rhs);
     }
     template<typename U>
     friend typename enable_if<boost::is_same<U, bool>, bool>::type
       operator!=( const Derived& lhs, U rhs )
     {
-      return cast<bool>(lhs) != rhs;
+      return bool(lhs) != rhs;
     }
     template<typename U>
     friend typename enable_if<boost::is_same<U, bool>, bool>::type
       operator!=( U lhs, const Derived& rhs )
     {
-      return lhs != cast<bool>(rhs);
+      return lhs != bool(rhs);
     }
     
   #else   // #ifndef GINTENLIB_BOOL_COMPARABLE_NO_ENABLE_IF
@@ -266,19 +259,19 @@ namespace gintenlib
     // この場合、 x == 1 のような表現が通ってしまうが仕方ないね
     friend bool operator==( const Derived& lhs, bool rhs )
     {
-      return cast<bool>(lhs) == rhs;
+      return bool(lhs) == rhs;
     }
     friend bool operator==( bool lhs, const Derived& rhs )
     {
-      return lhs == cast<bool>(rhs);
+      return lhs == bool(rhs);
     }
     friend bool operator!=( const Derived& lhs, bool rhs )
     {
-      return cast<bool>(lhs) != rhs;
+      return bool(lhs) != rhs;
     }
     friend bool operator!=( bool lhs, const Derived& rhs )
     {
-      return lhs != cast<bool>(rhs);
+      return lhs != bool(rhs);
     }
     
   #endif  // #ifndef GINTENLIB_BOOL_COMPARABLE_NO_ENABLE_IF
@@ -328,7 +321,7 @@ namespace gintenlib
    protected:
     // 派生クラス以外からの構築禁止
      bool_comparable() {}
-    ~bool_comparable() {}
+    // ~bool_comparable() {}  // trivial にしたい
     
   };  // class bool_comparable<Derived>