Boost logo

Boost Users :

From: John C. Femiani (john.femiani_at_[hidden])
Date: 2008-07-21 00:25:05


Robert Dailey wrote:
> Hi,
>
> I'm trying to create my own struct that is compatible with
> boost::mpl::or_ as well as boost::enable_if.
>
> I find that using boost::mpl::or_ requires that my structure have a
> 'type' member, and enable_if looks for 'value'. Must I define both?
> What is the proper way to handle this? Below is my structure:
>
> template< typename t_type >
> struct is_sink
> {
> typedef typename boost::mpl::or_<
> vfx::io::is_device<t_type>,
> boost::is_same<t_type, vfx::io::Sink>
> > type;
> };
>
> The above structure works perfectly fine with boost::mpl::or_, but
> does not work for boost::enable_if because it is looking for a 'value'
> member. I feel what it should be looking for is is_sink::type::value.
> An example of how I use the above structure is below:
>
> template< typename t_source, typename t_data >
> typename boost::enable_if<
> boost::mpl::and_<*is_source<t_source>*, boost::is_pod<t_data> >,
> t_source
> >::type& operator>> ( t_source& source, t_data& data )
> {
> source.Read( reinterpret_cast<boost::uint8_t*>( &data ), sizeof(
> t_data ) );
> return source;
> }
I think the condition has to satisfy this concept:
http://www.boost.org/doc/libs/1_35_0/libs/mpl/doc/refmanual/integral-constant.html

Anyhow, I think it is a lot easier in general to use inheritance for
metafunctions: i.e. (untested)

template< typename t_type >
struct is_sink:
    ::boost::mpl::or_<
        ::vfx::io::is_device<t_type>,
        ::boost::is_same<t_type, ::vfx::io::Sink>
>::type
{};

-- John Femiani


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net