这就是我最终做的事情:
template<
typename Derived
, typename Sequence
, typename TraversalTag =
typename boost::fusion::traits::category_of< Sequence >::type
, typename IsView =
typename boost::fusion::traits::is_view< Sequence >::type
>
class fusion_sequence_wrapper
: public boost::fusion::sequence_facade< Derived, TraversalTag, IsView >
{
typedef Sequence base_sequence_type;
public:
explicit fusion_sequence_wrapper( base_sequence_type const& sequence )
: _seq( sequence )
{}
base_sequence_type const& base() const
{
return _seq;
}
base_sequence_type& base()
{
return _seq;
}
public:
template< typename Seq >
struct begin
{
typedef
typename boost::fusion::result_of::begin<
typename boost::mpl::if_<
boost::is_const< Seq >
, base_sequence_type const
, base_sequence_type
>::type
>::type type;
static type call( Seq& s ){ return boost::fusion::begin( s._seq ); }
};
template< typename Seq >
struct end
{
typedef
typename boost::fusion::result_of::end<
typename boost::mpl::if_<
boost::is_const< Seq >
, base_sequence_type const
, base_sequence_type
>::type
>::type type;
static type call( Seq& s ){ return boost::fusion::end( s._seq ); }
};
template< typename Seq >
struct size
{
typedef
typename boost::fusion::result_of::size<
typename boost::mpl::if_<
boost::is_const< Seq >
, base_sequence_type const
, base_sequence_type
>::type
>::type type;
static type call( Seq& s ){ return boost::fusion::size( s._seq ); }
};
template< typename Seq >
struct empty
{
typedef
typename boost::fusion::result_of::empty<
typename boost::mpl::if_<
boost::is_const< Seq >
, base_sequence_type const
, base_sequence_type
>::type
>::type type;
static type call( Seq& s ){ return boost::fusion::empty( s._seq ); }
};
template< typename Seq, typename N >
struct at
{
typedef
typename boost::fusion::result_of::at<
typename boost::mpl::if_<
boost::is_const< Seq >
, base_sequence_type const
, base_sequence_type
>::type
, N
>::type type;
static type call( Seq& s ){ return boost::fusion::at( s._seq ); }
};
template< typename Seq, typename N >
struct value_at
{
typedef
typename boost::fusion::result_of::value_at<
typename boost::mpl::if_<
boost::is_const< Seq >
, base_sequence_type const
, base_sequence_type
>::type
, N
>::type type;
};
private:
base_sequence_type _seq;
};