Boost logo

Ublas :

Subject: Re: [ublas] Numeric traits for ublas bounded_vector and matrix
From: Jesse Perla (jesseperla_at_[hidden])
Date: 2010-02-23 11:26:06


Rutger ter Borg <rutger <at> terborg.net> writes:

> this happens to compile and work on my system.

You are right... I realize that the problem I had found was with a subtly
different pattern that is quite common. See the following:

static const int N = boost::mpl::eval_if<
    boost::numeric::bindings::has_static_size< double[10] >,
        boost::numeric::bindings::result_of::size< double[10] >::type,
    boost::mpl::int_<0>
>::value; //Note different access!

static const int J = boost::mpl::eval_if<
    boost::numeric::bindings::has_static_size< std::vector<double> >,
    boost::numeric::bindings::result_of::size< std::vector<double> >::type,
    boost::mpl::int_<0>
>::value;

Note here that the ::type is necessary here. But now that I look at it, The
problem may be that the result_of in this specific case doesn't use
metafunction forwarding, whereas my naive implementation of static_size did...
And hence it had the nested value automatically.

Also note that the following does NOT compile and looks like it should:

static const int N2 = boost::mpl::if_<
    boost::numeric::bindings::has_static_size< double[10] >,
        boost::numeric::bindings::result_of::size< double[10] >,
    boost::mpl::int_<0>
>::type::value;

static const int J2 = boost::mpl::if_<
    boost::numeric::bindings::has_static_size< std::vector<double> >,
    boost::numeric::bindings::result_of::size< std::vector<double> >,
    boost::mpl::int_<0>
>::type::value;

/////

When I wrote my naive static_size, it looked something like this:
template<typename T> struct static_vector_size_impl;

template<typename T, std::size_t N> struct
   static_vector_size_impl<ublas::bounded_vector<T, N>> : boost::mpl::int_<N>
{};
template<typename T> struct static_vector_size :
   static_vector_size_impl<remove_const_ref<T>::type>{};