SlideShare a Scribd company logo
Boost.Interfaces
Boost.Interfaces is Not a Boost library
・ライブラリ作ったよ! モチベーション (1)
struct  point { ... int  x()  const  {  return  x_; } int  y()  const  {  return  y_; } void  x( int  v) { x_ = v; } void  y( int  v) { y_ = v; } }; ・ライブラリ作ったよ! モチベーション (1)
struct  point { ... int  x()  const  {  return  x_; } int  y()  const  {  return  y_; } void  x( int  v) { x_ = v; } void  y( int  v) { y_ = v; } }; ・ライブラリ作ったよ! struct  rectangle { ... int  x()  const  {  return  x_; } int  y()  const  {  return  y_; } int  w()  const  {  return  w_; } int  h()  const  {  return  h_; } }; モチベーション (1)
・ライブラリ使うよ! モチベーション (2)
void  add(point& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } void  add(rectangle& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } ・ライブラリ使うよ! モチベーション (2)
・ライブラリ使うよ! void  add(point& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } void  add(rectangle& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (2)
・ライブラリ使うよ! void  add(point& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } void  add(rectangle& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } 完全に一致 モチベーション (2)
インターフェースさえ提供されていれば ... モチベーション (3)
インターフェースさえ提供されていれば ... void  add(IPoint& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (3)
インターフェースさえ提供されていれば ... void  add(IPoint& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? モチベーション (3)
インターフェースさえ提供されていれば ... void  add(IPoint& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? -> NO モチベーション (3)
インターフェースさえ提供されていれば ... void  add(IPoint& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? -> NO 使う側の要求するインターフェースを ライブラリが全て提供するのは無理ぽ モチベーション (3)
・それテンプレートでできるよ モチベーション (4)
・それテンプレートでできるよ template < class  Point> void  add(Point& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (4)
・それテンプレートでできるよ template < class  Point> void  add(Point& p,  int  n) { p.x(p.x() + n); p.y(p.y() + n); } テンプレートを使うことで ユーザが自由にインターフェースを定義できる モチベーション (4)
でも  is Not DEMO
テンプレートは持ち運べない モチベーション (5)
テンプレートは持ち運べない struct  point { void  draw() { ... } } pt; struct  rectangle { void  draw() { ... } } rc; モチベーション (5)
テンプレートは持ち運べない struct  point { void  draw() { ... } } pt; struct  rectangle { void  draw() { ... } } rc; std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d->draw(); モチベーション (5)
テンプレートは持ち運べない struct  point { void  draw() { ... } } pt; struct  rectangle { void  draw() { ... } } rc; こんな風に書きたいことがある std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d->draw(); モチベーション (5)
そこで  Boost.Interfaces
interface  Drawable { void  draw(); } Boost.Interfaces  の使い方
interface  Drawable { void  draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v)  d.draw(); Boost.Interfaces  の使い方
interface  Drawable { void  draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v)  d.draw(); ↑ ドットでアクセス Boost.Interfaces  の使い方
interface  Drawable { void  draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v)  d.draw(); 解決! ↑ ドットでアクセス Boost.Interfaces  の使い方
interface  Point { int  x()  const ; int  y()  const ; void  x( int  v); void  y( int  v); } Pseudocode Boost.Interfaces  クラス定義
int  x()  const ; int  y()  const ; void  x( int  v); void  y( int  v); } BOOST_IDL_BEGIN(Point) C++ code Boost.Interfaces  クラス定義
int  y()  const ; void  x( int  v); void  y( int  v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) C++ code Boost.Interfaces  クラス定義
void  x( int  v); void  y( int  v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) C++ code Boost.Interfaces  クラス定義
void  y( int  v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) C++ code Boost.Interfaces  クラス定義
} BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) C++ code Boost.Interfaces  クラス定義
BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) C++ code Boost.Interfaces  クラス定義
BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) 非常に明解で分かりやすい C++ code Boost.Interfaces  クラス定義
interface  Point { int  x()  const ; int  y()  const ; void  x( int  v); void  y( int  v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) 完全に一致 Pseudocode C++ code Boost.Interfaces  クラス定義
struct Point_interface_impl_ { static const int start_line_idl_ = 491; template<typename Base_> struct inner : Base_ { typedef typename ::boost::interfaces::advice_category< Base_ >::type category; private: friend class ::boost::interfaces::access; template<typename NNN_, typename Dummy_ = int> struct tracker_idl_ { typedef void type; }; public: struct supers_idl_ : ::boost::mpl::identity< ::boost::mpl::vector< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_  ) { return static_cast<XXX_*>(xxx_)->x(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_492 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self  ) { return invoker_type::execute( self  ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)()  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int x()  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_10; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_492<category, int> impl; return impl::execute( static_cast<const DDD_*>(this)  ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, int>; struct dummy_idl_492; void x(dummy_idl_492*) { } struct dummy_idl_492 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_  ) { return static_cast<XXX_*>(xxx_)->y(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_493 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self  ) { return invoker_type::execute( self  ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)()  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int y()  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_11; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_493<category, int> impl; return impl::execute( static_cast<const DDD_*>(this)  ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, int>; struct dummy_idl_493; void y(dummy_idl_493*) { } struct dummy_idl_493 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ ,  int xxx_0) { return static_cast<XXX_*>(xxx_)->x( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_494 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self ,  int xxx_0 ) { return invoker_type::execute( self ,  xxx_0 ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int)  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void x( int xxx_0)  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_12; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_494<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ,  xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, int>; struct dummy_idl_494; void x(dummy_idl_494*) { } struct dummy_idl_494 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ ,  int xxx_0) { return static_cast<XXX_*>(xxx_)->y( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_495 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self ,  int xxx_0 ) { return invoker_type::execute( self ,  xxx_0 ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int)  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void y( int xxx_0)  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_13; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_495<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ,  xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, int>; struct dummy_idl_495; void y(dummy_idl_495*) { } struct dummy_idl_495 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; public: struct index_idl_ { template<typename N> struct apply : tracker_idl_< ::boost::mpl::int_<N::value>, int > { }; }; }; };  class Point : public ::boost::interfaces::detail::interface_base< Point  , Point_interface_impl_  , 496 - Point_interface_impl_  ::start_line_idl_ >::type { private: typedef Point_interface_impl_  implementation_type; typedef  ::boost::interfaces::detail::interface_base< Point  , implementation_type, 496 - implementation_type::start_line_idl_ >::type base_idl_; friend class ::boost::interfaces::access; public: Point() : pv_idl_(0), table_idl_(0) { } template<typename XXX_> Point( XXX_& object_, typename ::boost::disable_if< ::boost::interfaces::is_interface<XXX_> >::type* = 0 ) : pv_idl_(&object_), table_idl_( ::boost::interfaces::detail::initialize_table<Point>(object_) ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!::boost::is_const<XXX_>::value) >)> boost_static_assert_typedef_14; } template<typename XXX_> Point( const XXX_& interface_, typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type > >::type* = 0 ) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type >::value; } Point& operator=(::boost::interfaces::detail::null_pointer_constant) { this->reset(); return *this; } private: template<typename XXX_> Point& operator=(const XXX_* ptr); public: template<typename XXX_> typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type >, Point& >::type operator=(const XXX_& interface_) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type >::value; return *this; } void reset() { pv_idl_ = 0; table_idl_ = 0; } operator const void*() const { return table_idl_; } private: const void* pv_idl_; const ::boost::interfaces::detail::fn_ptr* table_idl_; }; template< typename XXX_  > ::boost::type_traits::yes_type is_interface_helper( Point  *, XXX_*, typename ::boost::enable_if< ::boost::is_same< XXX_, Point  > >::type* = 0 ); Boost.Interfaces  クラス定義
struct Point_interface_impl_ { static const int start_line_idl_ = 491; template<typename Base_> struct inner : Base_ { typedef typename ::boost::interfaces::advice_category< Base_ >::type category; private: friend class ::boost::interfaces::access; template<typename NNN_, typename Dummy_ = int> struct tracker_idl_ { typedef void type; }; public: struct supers_idl_ : ::boost::mpl::identity< ::boost::mpl::vector< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_  ) { return static_cast<XXX_*>(xxx_)->x(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_492 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self  ) { return invoker_type::execute( self  ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)()  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int x()  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_10; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_492<category, int> impl; return impl::execute( static_cast<const DDD_*>(this)  ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, int>; struct dummy_idl_492; void x(dummy_idl_492*) { } struct dummy_idl_492 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_  ) { return static_cast<XXX_*>(xxx_)->y(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_493 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self  ) { return invoker_type::execute( self  ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)()  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int y()  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_11; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_493<category, int> impl; return impl::execute( static_cast<const DDD_*>(this)  ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, int>; struct dummy_idl_493; void y(dummy_idl_493*) { } struct dummy_idl_493 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ ,  int xxx_0) { return static_cast<XXX_*>(xxx_)->x( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_494 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self ,  int xxx_0 ) { return invoker_type::execute( self ,  xxx_0 ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int)  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void x( int xxx_0)  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_12; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_494<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ,  xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, int>; struct dummy_idl_494; void x(dummy_idl_494*) { } struct dummy_idl_494 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ ,  int xxx_0) { return static_cast<XXX_*>(xxx_)->y( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_495 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self ,  int xxx_0 ) { return invoker_type::execute( self ,  xxx_0 ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int)  > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void y( int xxx_0)  { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_13; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_495<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ,  xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, int>; struct dummy_idl_495; void y(dummy_idl_495*) { } struct dummy_idl_495 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; public: struct index_idl_ { template<typename N> struct apply : tracker_idl_< ::boost::mpl::int_<N::value>, int > { }; }; }; };  class Point : public ::boost::interfaces::detail::interface_base< Point  , Point_interface_impl_  , 496 - Point_interface_impl_  ::start_line_idl_ >::type { private: typedef Point_interface_impl_  implementation_type; typedef  ::boost::interfaces::detail::interface_base< Point  , implementation_type, 496 - implementation_type::start_line_idl_ >::type base_idl_; friend class ::boost::interfaces::access; public: Point() : pv_idl_(0), table_idl_(0) { } template<typename XXX_> Point( XXX_& object_, typename ::boost::disable_if< ::boost::interfaces::is_interface<XXX_> >::type* = 0 ) : pv_idl_(&object_), table_idl_( ::boost::interfaces::detail::initialize_table<Point>(object_) ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!::boost::is_const<XXX_>::value) >)> boost_static_assert_typedef_14; } template<typename XXX_> Point( const XXX_& interface_, typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type > >::type* = 0 ) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type >::value; } Point& operator=(::boost::interfaces::detail::null_pointer_constant) { this->reset(); return *this; } private: template<typename XXX_> Point& operator=(const XXX_* ptr); public: template<typename XXX_> typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type >, Point& >::type operator=(const XXX_& interface_) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_,  ::boost::interfaces::remove_qualifiers<Point>::type >::value; return *this; } void reset() { pv_idl_ = 0; table_idl_ = 0; } operator const void*() const { return table_idl_; } private: const void* pv_idl_; const ::boost::interfaces::detail::fn_ptr* table_idl_; }; template< typename XXX_  > ::boost::type_traits::yes_type is_interface_helper( Point  *, XXX_*, typename ::boost::enable_if< ::boost::is_same< XXX_, Point  > >::type* = 0 ); Boost.Interfaces  クラス定義 非常に明解で分かりやすい
ここからおまけ
interface  Point1D { int  x()  const ; } interface  WritablePoint1D : Point1D { void  x( int  v); } interface  Point2D : Point1D { int  y()  const ; } interface  WritablePoint2D : Point2D , WritablePoint1D { void  y( int  v); } インターフェースの継承もできる その他の機能 (1)
BOOST_IDL_BEGIN(Point1D) BOOST_IDL_FN0(x,  int ) BOOST_IDL_END(Point1D) BOOST_IDL_BEGIN(WritablePoint1D) BOOST_IDL_EXTENDS(Point1D) BOOST_IDL_FN1(x,  void ,  int ) BOOST_IDL_END(WritablePoint1D) BOOST_IDL_BEGIN(Point2D) BOOST_IDL_EXTENDS(Point1D) BOOST_IDL_FN0(y,  int ) BOOST_IDL_END(Point2D) BOOST_IDL_BEGIN(WritablePoint2D) BOOST_IDL_EXTENDS(Point2D) BOOST_IDL_EXTENDS(WritablePoint1D) BOOST_IDL_FN1(y,  void ,  int ) BOOST_IDL_END(Point2D) インターフェースの継承もできる その他の機能 (1)
テンプレートなインターフェース も定義できる template<class T> interface  Stack { bool  empty()  const ; void  push( const  T&); void  pop(); T& top(); const  T& top()  const ; }; その他の機能 (2)
テンプレートなインターフェース も定義できる template<class T> BOOST_IDL_BEGIN1(Stack) BOOST_IDL_CONST_FN0(empty,  bool ) BOOST_IDL_FN1(push,  void ,  const  T&) BOOST_IDL_FN0(pop,  void ) BOOST_IDL_FN0(top, T&) BOOST_IDL_CONST_FN0(top,  const  T&) BOOST_IDL_END1(Stack) その他の機能 (2)
Boost.Interfaces  は一切 コピーしない // d  は  rect  への 参照を保持 Drawable d = rect; //  コンパイルエラー Drawable d2 = rectangle(); // d3  は  rect  への 参照を保持 Drawable d3 = d; その他の機能 (3)
Boost.Interfaces  は一切 コピーしない // d  は  rect  への 参照を保持 Drawable d = rect; //  コンパイルエラー Drawable d2 = rectangle(); // d3  は  rect  への 参照を保持 Drawable d3 = d; Boost.Interfaces  はコピーを 要求しない その他の機能 (3)
boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new  point()); d->draw(); その他の機能 (4)
boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new  point()); d->draw(); boost::interfaces:: shared_obj で持ち運ぶ shared_obj<Drawable> d2( new  point()); d2.draw(); その他の機能 (4)
boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new  point()); d->draw(); boost::interfaces:: shared_obj で持ち運ぶ shared_obj<Drawable> d2( new  point()); d2.draw(); ↑ ドットでアクセス その他の機能 (4)
boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new  point()); d->draw(); boost::interfaces:: shared_obj で持ち運ぶ shared_obj<Drawable> d2( new  point()); d2.draw(); ↑ ドットでアクセス その他の機能 (4) unique_ptr, unique_obj  もあるよ!
キャスト shared_ptr<Drawable> d( new  point()); shared_obj<Drawable> d2( new  rectangle()); // OK point& p =  extract <point>(*d); // bad_extract point& p2 =  extract <point>(d2); その他の機能 (5)
Future  Directions
Aspect Oriented Programming (AOP) typedef  crosscut<  MyClass, aspect<Pointcut1, Advice1>, aspect<Pointcut2, Advice2>, ... , aspect<PointcutN, AdviceN> > MyCrosscutClass; ミライノハナシ (1)
リフレクション template < typename  Interface> void  f(Interface& i) { boost::function< void ( int )> f; if  (f = find_function< void ( int )>(i, &quot;foo&quot;)) f(3); } ミライノハナシ (2)
オペレーター オーバーロード interface  Hoge { int &  operator [] (std::size_t); }; ミライノハナシ (3)
オペレーター オーバーロード interface  Hoge { int &  operator [] (std::size_t); }; え、これできないの? ミライノハナシ (3)
テンプレートベースのインターフェース定義 BOOST_IDL_NAME(name) BOOST_IDL_NAME(rank) BOOST_IDL_NAME(serial_number) typedef  interface< extends<IPerson>, function<name,  const char *()>  const , function<rank,  const char *()>  const , function<serial_number,  long ()>  const > IPrisonerOfWar; ミライノハナシ (4)
おまけ終了
・インターフェース設計の遅延 まとめ
・インターフェース設計の遅延 ・インターフェースを持ち運べる まとめ
・インターフェース設計の遅延 ・ドットでアクセス ・インターフェースを持ち運べる まとめ
・インターフェース設計の遅延 ・ドットでアクセス ・未来は夢が溢れていて沈みそう ・インターフェースを持ち運べる まとめ
・インターフェース設計の遅延 ・ドットでアクセス ・未来は夢が溢れていて沈みそう ・現在のコードすらコンパイルエラーで修正したりとか ・インターフェースを持ち運べる まとめ
参考資料 Cryolite  先生 http ://d.hatena.ne.jp/Cryolite/20041130#p2 http://d.hatena.ne.jp/Cryolite/20041201#p1 http://d.hatena.ne.jp/Cryolite/20050205#p1 ABI  周りについて書いてあったり モチベーションについてもっと細かく書いてあったり 本家 http://www.coderage.com/interfaces/
ありがとうございました

More Related Content

PPS
pointers 1
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
PDF
c programming
PPTX
Unit 3
PDF
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
PDF
C++ L04-Array+String
PDF
c programming
pointers 1
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
c programming
Unit 3
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
C++ L04-Array+String
c programming

What's hot (20)

DOC
C tech questions
PPT
Pointer
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
PDF
Programming with GUTs
PDF
C++11 smart pointer
PPT
Pointers in C
PPT
Pointers+(2)
PPT
detailed information about Pointers in c language
PPTX
Smart pointers
TXT
Advance C++notes
PPTX
Pointers in C
PPT
Advance features of C++
PPTX
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
PDF
CS50 Lecture3
PDF
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
PDF
Keygenning using the Z3 SMT Solver
DOCX
C interview question answer 2
DOC
Captitude 2doc-100627004318-phpapp01
DOC
C aptitude.2doc
C tech questions
Pointer
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Programming with GUTs
C++11 smart pointer
Pointers in C
Pointers+(2)
detailed information about Pointers in c language
Smart pointers
Advance C++notes
Pointers in C
Advance features of C++
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
CS50 Lecture3
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Keygenning using the Z3 SMT Solver
C interview question answer 2
Captitude 2doc-100627004318-phpapp01
C aptitude.2doc
Ad

Similar to Boost.Interfaces (20)

PPTX
Boost tour 1_44_0_all
PDF
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
PPT
Practical Meta Programming
PPTX
C++ metaprogramming
PPTX
C++ metaprogramming
PDF
I am trying to create a program That works with two other programs i.pdf
DOC
Assignment Examples Final 07 Oct
PDF
Virtual Functions
PDF
第11回 配信講義 計算科学技術特論A(2021)
PDF
[E-Dev-Day 2014][5/16] C++ and JavaScript bindings for EFL and Elementary
PDF
Refactoring
PPT
C++ polymorphism
PDF
C++ extension methods
PDF
JVM code reading -- C2
PPS
C++ Language
PPT
Classes and Inheritance
PPT
Static and dynamic polymorphism
PPT
Static and dynamic polymorphism
PDF
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
Boost tour 1_44_0_all
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
Practical Meta Programming
C++ metaprogramming
C++ metaprogramming
I am trying to create a program That works with two other programs i.pdf
Assignment Examples Final 07 Oct
Virtual Functions
第11回 配信講義 計算科学技術特論A(2021)
[E-Dev-Day 2014][5/16] C++ and JavaScript bindings for EFL and Elementary
Refactoring
C++ polymorphism
C++ extension methods
JVM code reading -- C2
C++ Language
Classes and Inheritance
Static and dynamic polymorphism
Static and dynamic polymorphism
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
Ad

Boost.Interfaces

  • 2. Boost.Interfaces is Not a Boost library
  • 4. struct point { ... int x() const { return x_; } int y() const { return y_; } void x( int v) { x_ = v; } void y( int v) { y_ = v; } }; ・ライブラリ作ったよ! モチベーション (1)
  • 5. struct point { ... int x() const { return x_; } int y() const { return y_; } void x( int v) { x_ = v; } void y( int v) { y_ = v; } }; ・ライブラリ作ったよ! struct rectangle { ... int x() const { return x_; } int y() const { return y_; } int w() const { return w_; } int h() const { return h_; } }; モチベーション (1)
  • 7. void add(point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } void add(rectangle& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } ・ライブラリ使うよ! モチベーション (2)
  • 8. ・ライブラリ使うよ! void add(point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } void add(rectangle& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (2)
  • 9. ・ライブラリ使うよ! void add(point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } void add(rectangle& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } 完全に一致 モチベーション (2)
  • 11. インターフェースさえ提供されていれば ... void add(IPoint& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (3)
  • 12. インターフェースさえ提供されていれば ... void add(IPoint& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? モチベーション (3)
  • 13. インターフェースさえ提供されていれば ... void add(IPoint& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? -> NO モチベーション (3)
  • 14. インターフェースさえ提供されていれば ... void add(IPoint& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } 提供する側が IPoint を提供するべき? -> NO 使う側の要求するインターフェースを ライブラリが全て提供するのは無理ぽ モチベーション (3)
  • 16. ・それテンプレートでできるよ template < class Point> void add(Point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } モチベーション (4)
  • 17. ・それテンプレートでできるよ template < class Point> void add(Point& p, int n) { p.x(p.x() + n); p.y(p.y() + n); } テンプレートを使うことで ユーザが自由にインターフェースを定義できる モチベーション (4)
  • 18. でも is Not DEMO
  • 20. テンプレートは持ち運べない struct point { void draw() { ... } } pt; struct rectangle { void draw() { ... } } rc; モチベーション (5)
  • 21. テンプレートは持ち運べない struct point { void draw() { ... } } pt; struct rectangle { void draw() { ... } } rc; std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d->draw(); モチベーション (5)
  • 22. テンプレートは持ち運べない struct point { void draw() { ... } } pt; struct rectangle { void draw() { ... } } rc; こんな風に書きたいことがある std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d->draw(); モチベーション (5)
  • 24. interface Drawable { void draw(); } Boost.Interfaces の使い方
  • 25. interface Drawable { void draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d.draw(); Boost.Interfaces の使い方
  • 26. interface Drawable { void draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d.draw(); ↑ ドットでアクセス Boost.Interfaces の使い方
  • 27. interface Drawable { void draw(); } std::vector<Drawable> v; v.push_back(pt); v.push_back(rc); BOOST_FOREACH(Drawable& d, v) d.draw(); 解決! ↑ ドットでアクセス Boost.Interfaces の使い方
  • 28. interface Point { int x() const ; int y() const ; void x( int v); void y( int v); } Pseudocode Boost.Interfaces クラス定義
  • 29. int x() const ; int y() const ; void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) C++ code Boost.Interfaces クラス定義
  • 30. int y() const ; void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) C++ code Boost.Interfaces クラス定義
  • 31. void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) C++ code Boost.Interfaces クラス定義
  • 32. void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) C++ code Boost.Interfaces クラス定義
  • 33. } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) C++ code Boost.Interfaces クラス定義
  • 34. BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) C++ code Boost.Interfaces クラス定義
  • 35. BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) 非常に明解で分かりやすい C++ code Boost.Interfaces クラス定義
  • 36. interface Point { int x() const ; int y() const ; void x( int v); void y( int v); } BOOST_IDL_BEGIN(Point) BOOST_IDL_CONST_FN0(x, int) BOOST_IDL_CONST_FN0(y, int) BOOST_IDL_FN1(x, void, int) BOOST_IDL_FN1(y, void, int) BOOST_IDL_END(Point) 完全に一致 Pseudocode C++ code Boost.Interfaces クラス定義
  • 37. struct Point_interface_impl_ { static const int start_line_idl_ = 491; template<typename Base_> struct inner : Base_ { typedef typename ::boost::interfaces::advice_category< Base_ >::type category; private: friend class ::boost::interfaces::access; template<typename NNN_, typename Dummy_ = int> struct tracker_idl_ { typedef void type; }; public: struct supers_idl_ : ::boost::mpl::identity< ::boost::mpl::vector< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->x(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_492 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int x() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_10; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_492<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, int>; struct dummy_idl_492; void x(dummy_idl_492*) { } struct dummy_idl_492 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->y(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_493 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int y() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_11; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_493<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, int>; struct dummy_idl_493; void y(dummy_idl_493*) { } struct dummy_idl_493 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->x( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_494 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void x( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_12; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_494<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, int>; struct dummy_idl_494; void x(dummy_idl_494*) { } struct dummy_idl_494 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->y( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_495 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void y( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_13; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_495<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, int>; struct dummy_idl_495; void y(dummy_idl_495*) { } struct dummy_idl_495 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; public: struct index_idl_ { template<typename N> struct apply : tracker_idl_< ::boost::mpl::int_<N::value>, int > { }; }; }; }; class Point : public ::boost::interfaces::detail::interface_base< Point , Point_interface_impl_ , 496 - Point_interface_impl_ ::start_line_idl_ >::type { private: typedef Point_interface_impl_ implementation_type; typedef ::boost::interfaces::detail::interface_base< Point , implementation_type, 496 - implementation_type::start_line_idl_ >::type base_idl_; friend class ::boost::interfaces::access; public: Point() : pv_idl_(0), table_idl_(0) { } template<typename XXX_> Point( XXX_& object_, typename ::boost::disable_if< ::boost::interfaces::is_interface<XXX_> >::type* = 0 ) : pv_idl_(&object_), table_idl_( ::boost::interfaces::detail::initialize_table<Point>(object_) ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!::boost::is_const<XXX_>::value) >)> boost_static_assert_typedef_14; } template<typename XXX_> Point( const XXX_& interface_, typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type > >::type* = 0 ) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; } Point& operator=(::boost::interfaces::detail::null_pointer_constant) { this->reset(); return *this; } private: template<typename XXX_> Point& operator=(const XXX_* ptr); public: template<typename XXX_> typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >, Point& >::type operator=(const XXX_& interface_) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; return *this; } void reset() { pv_idl_ = 0; table_idl_ = 0; } operator const void*() const { return table_idl_; } private: const void* pv_idl_; const ::boost::interfaces::detail::fn_ptr* table_idl_; }; template< typename XXX_ > ::boost::type_traits::yes_type is_interface_helper( Point *, XXX_*, typename ::boost::enable_if< ::boost::is_same< XXX_, Point > >::type* = 0 ); Boost.Interfaces クラス定義
  • 38. struct Point_interface_impl_ { static const int start_line_idl_ = 491; template<typename Base_> struct inner : Base_ { typedef typename ::boost::interfaces::advice_category< Base_ >::type category; private: friend class ::boost::interfaces::access; template<typename NNN_, typename Dummy_ = int> struct tracker_idl_ { typedef void type; }; public: struct supers_idl_ : ::boost::mpl::identity< ::boost::mpl::vector< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->x(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_492 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int x() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_10; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_492<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<492 - start_line_idl_>, int>; struct dummy_idl_492; void x(dummy_idl_492*) { } struct dummy_idl_492 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static int invoke(void* xxx_ ) { return static_cast<XXX_*>(xxx_)->y(); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_493 { typedef int signature(); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static int execute( const DDD_* self ) { return invoker_type::execute( self ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< int (XXX_::*MemFun)() > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; int y() { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_11; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_493<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<493 - start_line_idl_>, int>; struct dummy_idl_493; void y(dummy_idl_493*) { } struct dummy_idl_493 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->x( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct x_function_impl_494 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::x; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::x >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void x( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_12; typedef ::boost::interfaces::null_advice_tag category; typedef x_function_impl_494<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<494 - start_line_idl_>, int>; struct dummy_idl_494; void x(dummy_idl_494*) { } struct dummy_idl_494 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; private: template<typename Dummy_> struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, Dummy_> { typedef ::boost::interfaces::detail::fn_ptr fn_ptr; template<typename XXX_> struct invoker { static void invoke(void* xxx_ , int xxx_0) { return static_cast<XXX_*>(xxx_)->y( xxx_0); } }; struct type { template< typename DDD_, typename OOO_, typename FFF_, typename BBB_ > struct apply { template<typename Category, typename Dummy2_> struct y_function_impl_495 { typedef void signature( int xxx_0); typedef ::boost::interfaces::detail::null_invoker< DDD_, OOO_, signature > invoker_type; static void execute( const DDD_* self , int xxx_0 ) { return invoker_type::execute( self , xxx_0 ); } }; struct type : BBB_ { using BBB_::y; typedef typename BBB_::interface_advice interface_advice; struct interface_initializer { static const int size = 1; template<typename XXX_> static void initialize(fn_ptr* fns) { fns[OOO_::value] = reinterpret_cast<fn_ptr>(&invoker<XXX_>::invoke); } }; template<typename XXX_> struct interface_implemented { template< void (XXX_::*MemFun)( int) > struct holder { }; typedef char (&yes) [1]; typedef char (&no) [2]; template<typename YYY_> static no tester(...); template<typename YYY_> static yes tester( holder<&YYY_::y >* = 0 ); static const bool value = sizeof(tester<XXX_>(0)) == sizeof(yes); typedef ::boost::mpl::bool_<value> type; }; void y( int xxx_0) { using namespace ::boost::interfaces; typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!(FFF_::value & flags::is_const) || 0) >)> boost_static_assert_typedef_13; typedef ::boost::interfaces::null_advice_tag category; typedef y_function_impl_495<category, int> impl; return impl::execute( static_cast<const DDD_*>(this) , xxx_0 ); } }; }; }; }; friend struct tracker_idl_< ::boost::mpl::int_<495 - start_line_idl_>, int>; struct dummy_idl_495; void y(dummy_idl_495*) { } struct dummy_idl_495 : ::boost::interfaces::detail::dummy< ::boost::interfaces::detail::dummy< ::boost::mpl::na > > { }; public: struct index_idl_ { template<typename N> struct apply : tracker_idl_< ::boost::mpl::int_<N::value>, int > { }; }; }; }; class Point : public ::boost::interfaces::detail::interface_base< Point , Point_interface_impl_ , 496 - Point_interface_impl_ ::start_line_idl_ >::type { private: typedef Point_interface_impl_ implementation_type; typedef ::boost::interfaces::detail::interface_base< Point , implementation_type, 496 - implementation_type::start_line_idl_ >::type base_idl_; friend class ::boost::interfaces::access; public: Point() : pv_idl_(0), table_idl_(0) { } template<typename XXX_> Point( XXX_& object_, typename ::boost::disable_if< ::boost::interfaces::is_interface<XXX_> >::type* = 0 ) : pv_idl_(&object_), table_idl_( ::boost::interfaces::detail::initialize_table<Point>(object_) ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)(!::boost::is_const<XXX_>::value) >)> boost_static_assert_typedef_14; } template<typename XXX_> Point( const XXX_& interface_, typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type > >::type* = 0 ) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; } Point& operator=(::boost::interfaces::detail::null_pointer_constant) { this->reset(); return *this; } private: template<typename XXX_> Point& operator=(const XXX_* ptr); public: template<typename XXX_> typename ::boost::enable_if< ::boost::interfaces::is_base_and_derived< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >, Point& >::type operator=(const XXX_& interface_) { ::boost::interfaces::detail::fat_pointer ptr(interface_); pv_idl_ = ptr.pv; table_idl_ = ptr.table + ::boost::interfaces::detail::offset_of< XXX_, ::boost::interfaces::remove_qualifiers<Point>::type >::value; return *this; } void reset() { pv_idl_ = 0; table_idl_ = 0; } operator const void*() const { return table_idl_; } private: const void* pv_idl_; const ::boost::interfaces::detail::fn_ptr* table_idl_; }; template< typename XXX_ > ::boost::type_traits::yes_type is_interface_helper( Point *, XXX_*, typename ::boost::enable_if< ::boost::is_same< XXX_, Point > >::type* = 0 ); Boost.Interfaces クラス定義 非常に明解で分かりやすい
  • 40. interface Point1D { int x() const ; } interface WritablePoint1D : Point1D { void x( int v); } interface Point2D : Point1D { int y() const ; } interface WritablePoint2D : Point2D , WritablePoint1D { void y( int v); } インターフェースの継承もできる その他の機能 (1)
  • 41. BOOST_IDL_BEGIN(Point1D) BOOST_IDL_FN0(x, int ) BOOST_IDL_END(Point1D) BOOST_IDL_BEGIN(WritablePoint1D) BOOST_IDL_EXTENDS(Point1D) BOOST_IDL_FN1(x, void , int ) BOOST_IDL_END(WritablePoint1D) BOOST_IDL_BEGIN(Point2D) BOOST_IDL_EXTENDS(Point1D) BOOST_IDL_FN0(y, int ) BOOST_IDL_END(Point2D) BOOST_IDL_BEGIN(WritablePoint2D) BOOST_IDL_EXTENDS(Point2D) BOOST_IDL_EXTENDS(WritablePoint1D) BOOST_IDL_FN1(y, void , int ) BOOST_IDL_END(Point2D) インターフェースの継承もできる その他の機能 (1)
  • 42. テンプレートなインターフェース も定義できる template<class T> interface Stack { bool empty() const ; void push( const T&); void pop(); T& top(); const T& top() const ; }; その他の機能 (2)
  • 43. テンプレートなインターフェース も定義できる template<class T> BOOST_IDL_BEGIN1(Stack) BOOST_IDL_CONST_FN0(empty, bool ) BOOST_IDL_FN1(push, void , const T&) BOOST_IDL_FN0(pop, void ) BOOST_IDL_FN0(top, T&) BOOST_IDL_CONST_FN0(top, const T&) BOOST_IDL_END1(Stack) その他の機能 (2)
  • 44. Boost.Interfaces は一切 コピーしない // d は rect への 参照を保持 Drawable d = rect; // コンパイルエラー Drawable d2 = rectangle(); // d3 は rect への 参照を保持 Drawable d3 = d; その他の機能 (3)
  • 45. Boost.Interfaces は一切 コピーしない // d は rect への 参照を保持 Drawable d = rect; // コンパイルエラー Drawable d2 = rectangle(); // d3 は rect への 参照を保持 Drawable d3 = d; Boost.Interfaces はコピーを 要求しない その他の機能 (3)
  • 46. boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new point()); d->draw(); その他の機能 (4)
  • 47. boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new point()); d->draw(); boost::interfaces:: shared_obj で持ち運ぶ shared_obj<Drawable> d2( new point()); d2.draw(); その他の機能 (4)
  • 48. boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new point()); d->draw(); boost::interfaces:: shared_obj で持ち運ぶ shared_obj<Drawable> d2( new point()); d2.draw(); ↑ ドットでアクセス その他の機能 (4)
  • 49. boost::interfaces::shared_ptr で持ち運ぶ shared_ptr<Drawable> d( new point()); d->draw(); boost::interfaces:: shared_obj で持ち運ぶ shared_obj<Drawable> d2( new point()); d2.draw(); ↑ ドットでアクセス その他の機能 (4) unique_ptr, unique_obj もあるよ!
  • 50. キャスト shared_ptr<Drawable> d( new point()); shared_obj<Drawable> d2( new rectangle()); // OK point& p = extract <point>(*d); // bad_extract point& p2 = extract <point>(d2); その他の機能 (5)
  • 52. Aspect Oriented Programming (AOP) typedef crosscut< MyClass, aspect<Pointcut1, Advice1>, aspect<Pointcut2, Advice2>, ... , aspect<PointcutN, AdviceN> > MyCrosscutClass; ミライノハナシ (1)
  • 53. リフレクション template < typename Interface> void f(Interface& i) { boost::function< void ( int )> f; if (f = find_function< void ( int )>(i, &quot;foo&quot;)) f(3); } ミライノハナシ (2)
  • 54. オペレーター オーバーロード interface Hoge { int & operator [] (std::size_t); }; ミライノハナシ (3)
  • 55. オペレーター オーバーロード interface Hoge { int & operator [] (std::size_t); }; え、これできないの? ミライノハナシ (3)
  • 56. テンプレートベースのインターフェース定義 BOOST_IDL_NAME(name) BOOST_IDL_NAME(rank) BOOST_IDL_NAME(serial_number) typedef interface< extends<IPerson>, function<name, const char *()> const , function<rank, const char *()> const , function<serial_number, long ()> const > IPrisonerOfWar; ミライノハナシ (4)
  • 62. ・インターフェース設計の遅延 ・ドットでアクセス ・未来は夢が溢れていて沈みそう ・現在のコードすらコンパイルエラーで修正したりとか ・インターフェースを持ち運べる まとめ
  • 63. 参考資料 Cryolite 先生 http ://d.hatena.ne.jp/Cryolite/20041130#p2 http://d.hatena.ne.jp/Cryolite/20041201#p1 http://d.hatena.ne.jp/Cryolite/20050205#p1 ABI 周りについて書いてあったり モチベーションについてもっと細かく書いてあったり 本家 http://www.coderage.com/interfaces/