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
{
// ヘルパ構造体
// 派生したクラスを得る関数
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;
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
// この場合、 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
protected:
// 派生クラス以外からの構築禁止
bool_comparable() {}
- ~bool_comparable() {}
+ // ~bool_comparable() {} // trivial にしたい
}; // class bool_comparable<Derived>