范围可用于对Boost多维数组(multi_array)进行切片。根据的说法,有几种定义范围的方法,但并不是所有的方法都能编译。我在Ubuntu 11.04上使用的是GCC 4.5.2。
#include <boost/multi_array.hpp>
int main() {
typedef boost::multi_array_types::index_range range;
range a_range;
// indices i where 3 <= i
// Does compile
a_range = range
我有一个名为DataView的函数,它执行“切片”(创建array_view),如下所示:
template <class T>
typename Boost<T>::Array2D::template array_view<2>::type MyArray<T>::DataView(int x_start, int x_finish, int y_start, int y_finish)
{
using range = boost::multi_array_types::index_range;
return _Data[b
我的计划是在boost库的多维数组multi_array中存储数百(甚至数千)(插值)函数。我需要存储它们,因为我需要用不同的数字作为参数在项目的不同点调用它们。(我正在使用linterp库创建插值函数)。
我可以将函数存储在向量中,如下所示:
// creating the vector, storing the function
std::vector< std::function< double(double *x) > > interp_list(4);
// storing the function in the vector
interp_list[0] =
假设我需要一个五维数组作为类成员,并希望在不同的函数中使用它。对于这个puropose,我使用boost::multi_array,例如:
class myClass {
typedef boost::multiarray<double, 5> fiveDim;
typedef fiveDim:: index index;
void init(){
fiveDim myArray(boost::extents[3][3][3][3][3]);
// I can use myArray in this scope
}
void printArray(){
// myArray
在迭代器类型中使用->时,我会遇到一些错误。当我在定义迭代器的库中挖掘时,在我看来,每件事都是正常的,并且没有错误的理由。下面是代码,是boost::multi_array的一部分:
template <class T>
struct operator_arrow_proxy
{
operator_arrow_proxy(T const& px) : value_(px) {}
T* operator->() const { return &value_; }
// This function is needed for MWCW and B
我必须使用A类作为元素创建一个三维数组,A类的定义如下所示,我应该使用vector<vector<vector<A> > >还是boost::multi_array?哪一个更好?
struct C
{
int C_1;
short C_2;
};
class B
{
public:
bool B_1;
vector<C> C_;
};
class A
{
public:
bool A_1;
B B_[6];
};
这是来自和编译没有问题。
#include "boost/multi_array.hpp"
int main () {
// Create a 3D array that is 3 x 4 x 2
typedef boost::multi_array<double,3> array_type;
typedef array_type::index index;
array_type A(boost::extents[3][4][2]);
return 0;
}
,我的问题是:第二个模板参数是什么?,从文档中我不清楚。此代码只有