#include "bool_comparable.hpp"
#include <cassert>
+#include <functional> // for std::less
#include <boost/type_traits/add_reference.hpp>
namespace gintenlib
{
template< typename Derived, typename T, typename Category = Derived >
- struct pointer_facade
- : bool_comparable< pointer_facade< Derived, T, Category > >
+ class pointer_facade
+ : public bool_comparable< pointer_facade< Derived, T, Category > >
{
+ typedef pointer_facade<Derived, T, Category> this_type;
+
+ public:
// スマートポインタとして必要なあれこれ
typedef T element_type;
typedef T value_type;
}
// operator safe_bool は bool_comparable の管轄
- // 等値比較などは外部のテンプレートで実装
-
- private:
- template<typename D, typename U, typename C>
- friend class pointer_facade;
+ // 相互比較は外部で定義する
+ private:
// 派生クラスの get() を呼び出す
pointer get_() const
{
}; // pointer_facade<Derived, T, Category>
- // テンプレート版相互比較
+ // 相互比較
// カテゴリが同じものなら相互比較OK
template<typename T, typename U, typename D1, typename D2, typename C>
inline bool operator==( const pointer_facade<D1, T, C>& lhs, const pointer_facade<D2, U, C>& rhs )
{
return static_cast<const D1&>(lhs).get() != static_cast<const D2&>(rhs).get();
}
+
+ // < は、ポインタ型が同じ場合とそうでない場合で分ける
+ template<typename T, typename D, typename C>
+ inline bool operator< ( const pointer_facade<D, T, C>& lhs, const pointer_facade<D, T, C>& rhs )
+ {
+ // 同じポインタの比較は std::less で比較する
+ return std::less<T*>()( static_cast<const D&>(lhs).get(), static_cast<const D&>(rhs).get() );
+ }
template<typename T, typename U, typename D1, typename D2, typename C>
inline bool operator< ( const pointer_facade<D1, T, C>& lhs, const pointer_facade<D2, U, C>& rhs )
{
- // 異なるポインタ同士の比較は、
- // boost::shared_ptr で < を使ってるので、ここでも < で比較する
+ // 異なるポインタ同士の比較は、仕方ないので < で比較する
return static_cast<const D1&>(lhs).get() < static_cast<const D2&>(rhs).get();
}