It is said that we'd better use a multi_array builder if we want to use the multi_array more efficiently. However, I'm so new to both template and boost, I tried to copy some code from a book. It looks like this:
class multi_builder : boost::noncopyable
{
public:
typedef boost::multi_array<T,N> array_type;
typedef boost::shared_ptr<array_type > type;
private:
boost::any ext;
public:
multi_builder() : ext(boost::extents){}
~multi_builder(){}
template<std::size_t n>
void dim(std::size_t x)
{
BOOST_STATIC_ASSERT(n >= 0 && n < N);
ext = boost::any_cast<boost::detail::multi_array::extent_gen<n> >(ext) [x];
}
boost::type create(void)
{
return boost::type<array_type>(new array_type(boost::any_cast<boost::detail::multi_array::extent_gen<N> >(ext)));
}
};
However, when I tried to use it in the code like this:
multi_builder<int,2> builder;
builder.dim<0>(2);
builder.dim<1>(2);
BOOST_AUTO(mp,builder.create());
for(int i = 0,v = 0; i < 2; ++i)
for(int j = 0; j < 2; ++j)
(*mp)[i][j] = v++;
the compiler generates the following errors:
error:invalid use of template-name 'boost::type' without an argument list
error:'class multi_builder<int, 2u>' has no member named 'create'.
error:invalid type in declaration before '=' token
error:'class multi_builder<int, 2u>' has no member named 'create'
error:invalid type argument of 'unary *'
Could someone tell me how to fix the errors?