16

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 ==========
5
  • 1
    Replace extents[5][6] with boost::extents[5][6] in the call to resize. Commented Feb 2, 2011 at 2:27
  • 1
    No still skrews up. I'm following the tutorial/documentation on this one. Commented Feb 2, 2011 at 2:57
  • 1
    Very strange, I can copy-paste your code into the same compiler and it works. Commented Feb 2, 2011 at 4:26
  • It compiles under GCC 3.4.6 too. Commented Feb 2, 2011 at 4:50
  • 2
    Which version of Boost are you using? Commented Feb 2, 2011 at 7:49

3 Answers 3

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm still having this issue even on version 1.67 of boost. Here's a very basic code sample (~20 lines). pastebin.com/h8D5JYLf that can reproduce the issue. Not sure what the next step is here.
4

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

2 Comments

this is fixed in the upcoming version (1.49.0), and above fix I suggest is not quite safe. So, please upgrade!
Version 1.49 has the same issue.
1

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]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.