Yelnats
Yelnats

Reputation: 335

boost::multi_array resize doesn't work

I can't get boost::multi_array resizing to work. When I try it, it gives errors about std::_Copy_impl and the like. Here is the code

#include <boost/multi_array.hpp>

typedef boost::multi_array<int, 2> array_type;

class arrayclass{
public:
    arrayclass(array_type::extent_gen extents)
        : multiarray(extents[3][4]){
    }
    array_type multiarray;
};

int main(){
    array_type::extent_gen extents;
    arrayclass arraytest(extents);
    arraytest.multiarray.resize(extents[5][6]);
    return 0;
}

Edit: Here are the errors

1>------ Build started: Project: multiarray, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2216): error C2665: 'std::_Copy_impl' : none of the 2 overloads could convert all the argument types
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2182): could be '_OutIt std::_Copy_impl<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::input_iterator_tag,std::output_iterator_tag)'
1>          with
1>          [
1>              _OutIt=boost::detail::multi_array::array_iterator<int,int *,boost::mpl::size_t<2>,boost::detail::multi_array::sub_array<int,1>>,
1>              _InIt=boost::detail::multi_array::array_iterator<int,const int *,boost::mpl::size_t<2>,boost::detail::multi_array::const_sub_array<int,1>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2191): or       '_OutIt std::_Copy_impl<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::random_access_iterator_tag,std::random_access_iterator_tag)'
1>          with
1>          [
1>              _OutIt=boost::detail::multi_array::array_iterator<int,int *,boost::mpl::size_t<2>,boost::detail::multi_array::sub_array<int,1>>,
1>              _InIt=boost::detail::multi_array::array_iterator<int,const int *,boost::mpl::size_t<2>,boost::detail::multi_array::const_sub_array<int,1>>
1>          ]
1>          while trying to match the argument list '(boost::detail::multi_array::array_iterator<T,TPtr,NumDims,Reference>, boost::detail::multi_array::array_iterator<T,TPtr,NumDims,Reference>, boost::detail::multi_array::array_iterator<T,TPtr,NumDims,Reference>, boost::detail::iterator_category_with_traversal<Category,Traversal>, boost::detail::iterator_category_with_traversal<Category,Traversal>)'
1>          with
1>          [
1>              T=int,
1>              TPtr=const int *,
1>              NumDims=boost::mpl::size_t<2>,
1>              Reference=boost::detail::multi_array::const_sub_array<int,1>
1>          ]
1>          and
1>          [
1>              T=int,
1>              TPtr=const int *,
1>              NumDims=boost::mpl::size_t<2>,
1>              Reference=boost::detail::multi_array::const_sub_array<int,1>
1>          ]
1>          and
1>          [
1>              T=int,
1>              TPtr=int *,
1>              NumDims=boost::mpl::size_t<2>,
1>              Reference=boost::detail::multi_array::sub_array<int,1>
1>          ]
1>          and
1>          [
1>              Category=std::input_iterator_tag,
1>              Traversal=boost::random_access_traversal_tag
1>          ]
1>          and
1>          [
1>              Category=std::input_iterator_tag,
1>              Traversal=boost::random_access_traversal_tag
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2227) : see reference to function template instantiation '_OutIt std::_Copy_impl<_Iter,_OutIt>(_InIt,_InIt,_OutIt,std::tr1::false_type)' being compiled
1>          with
1>          [
1>              _OutIt=boost::detail::multi_array::array_iterator<int,int *,boost::mpl::size_t<2>,boost::detail::multi_array::sub_array<int,1>>,
1>              _Iter=boost::detail::multi_array::array_iterator<int,const int *,boost::mpl::size_t<2>,boost::detail::multi_array::const_sub_array<int,1>>,
1>              _InIt=boost::detail::multi_array::array_iterator<int,const int *,boost::mpl::size_t<2>,boost::detail::multi_array::const_sub_array<int,1>>
1>          ]
1>          c:\boost_1_45_0\boost\multi_array\view.hpp(321) : see reference to function template instantiation '_OutIt std::copy<boost::detail::multi_array::array_iterator<T,TPtr,NumDims,Reference>,boost::detail::multi_array::array_iterator<T,T *,NumDims,boost::detail::multi_array::sub_array<T,1>>>(_InIt,_InIt,_OutIt)' being compiled
1>          with
1>          [
1>              _OutIt=boost::detail::multi_array::array_iterator<int,int *,boost::mpl::size_t<2>,boost::detail::multi_array::sub_array<int,1>>,
1>              T=int,
1>              TPtr=const int *,
1>              NumDims=boost::mpl::size_t<2>,
1>              Reference=boost::detail::multi_array::const_sub_array<int,1>,
1>              _InIt=boost::detail::multi_array::array_iterator<int,const int *,boost::mpl::size_t<2>,boost::detail::multi_array::const_sub_array<int,1>>
1>          ]
1>          c:\boost_1_45_0\boost\multi_array\view.hpp(313) : while compiling class template member function 'boost::detail::multi_array::multi_array_view<T,NumDims> &boost::detail::multi_array::multi_array_view<T,NumDims>::operator =(const boost::detail::multi_array::multi_array_view<T,NumDims> &)'
1>          with
1>          [
1>              T=int,
1>              NumDims=2
1>          ]
1>          c:\badprogramer\multiarray\multiarray\main.cpp(7) : see reference to class template instantiation 'boost::detail::multi_array::multi_array_view<T,NumDims>' being compiled
1>          with
1>          [
1>              T=int,
1>              NumDims=2
1>          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Upvotes: 16

Views: 3448

Answers (3)

sly
sly

Reputation: 1780

A bit stale thread, but I see this is an issue with even the most recent VS 2010 and Boost 1.47.0. This is in fact a problem with Boost.MultiArray, hard to believe, I know!

To fix, edit boost code:

  • Open boost/multi_array/iterator.hpp
  • Replace first occurrence of boost::random_access_traversal_tag (Line 57 in version 1.47.0)
    with std::random_access_iterator_tag
  • Search second (line 75), replace that whole typedef with

    typedef typename array_iterator::iterator_facade_ facade_type;

hth

Upvotes: 4

Altren
Altren

Reputation: 39

Another workaround, that solved my problem is replacing

array_type multiarray;

with

array_type* multiarray;

and whenever you need to resize your array use

delete arraytest.multiarray;
arraytest.multiarray = new array_type(extents[5][6]);

Upvotes: 1

Hertzel Guinness
Hertzel Guinness

Reputation: 5950

This is reproducible with VS10 (using the proper VS10 headers) + boost 1.44 and in debug configuration (according to doc in older versions of boost as well).

The short workaround (until next c++ SP) is to

#define _ITERATOR_DEBUG_LEVEL 0

before everything else (specifically before STL includes).

There are more complicated possible solutions - see this similar thread.

Cheers

Upvotes: 7

Related Questions