我用
std::fill(foo.begin() , foo.end() , 0);
解决我的问题(不知道这是否是更好然后升压::分配,因为我无法应用它)。
与boo
我仍然有问题,因为 std :: fill(boo.begin() - > begin(),boo.end() - > end(),0); 通编译,但是当我运行我的程序,我得到以下错误:
/usr/include/boost/multi_array/base.hpp:178: Reference boost::detail::multi_array::value_accessor_one::access(boost::type, boost::multi_array_types::index, TPtr, const boost::multi_array_types::size_type*, const boost::multi_array_types::index*, const boost::multi_array_types::index*) const [with Reference = unsigned int&, TPtr = unsigned int*, T = unsigned int]: Assertion `size_type(idx - index_bases[0]) < extents[0]' failed.Blockquote
这里是一个短代码:
#include <iomanip>
#include "boost/multi_array.hpp"
#include <iostream>
namespace vec {
typedef boost::multi_array<unsigned int, 1> uint_1d_vec_t;
typedef boost::multi_array<unsigned int, 2> uint_2d_vec_t;
typedef uint_1d_vec_t::index index_1d_t;
typedef uint_2d_vec_t::index index_2d_t;
}
using namespace std;
int main() {
unsigned int num_elements, num_bits, max_runs, m;
num_bits = 12;
max_runs = 5000;
m = 2;
num_elements = (1 << num_bits);
double kappa = 79;
vec::uint_1d_vec_t foo(boost::extents[ static_cast<vec::index_1d_t>(num_elements) ] );
vec::uint_2d_vec_t boo(boost::extents[ static_cast<vec::index_2d_t>(num_elements) ][ static_cast<vec::index_2d_t>(kappa) ]);
std::fill(foo.begin() , foo.end() , 0);
std::fill(boo.begin()->begin() , boo.end()->end() , 0);
std::cout << "Done" << std::endl;
return EXIT_SUCCESS;
}
@Octavian:谢谢,但在标题中添加标签与清理相反。 – 2012-01-31 17:19:59
@LightnessRacesinOrbit这似乎是个人观点。 [我如何写一个好的标题?](http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title)。 – 2012-01-31 19:00:43
@OctavianDamiean:这个主题的主流观点是标题中的标签不好。我们已经有了一个一致的索引标签系统。 Mods在过去也支持我进行这样的编辑。当然,不能取悦每个人。 – 2012-01-31 19:47:14