stl - Implement Iterators Even When Not Needed? C++ -


i have container called "ntuple" c array , length. it's main purpose argument of multi-dimensional math functions. of now, it's fast , utilizes several constructors of form

ntuple(double x, double y, double z) {     size = 3;     vec = new double[size];     vec[0] = x;     vec[1] = y;     vec[2] = z; } 

and every time work higher dimensional, yet known function, add new constructor. have on array well:

ntuple(double* invec, long unsigned insizesize) 

in order make code more compatible regular c++ code, should implement ntuple iterator class? nothing i've done has needed 1 , seems slow down. more read, more vital seems use iterators sake of compatibility standard c++ code.

i worry when tries work code, won't mesh standard techniques expect use. purpose of ntuple class take arguments functions.

should implement iterators precaution (if else try use stl on it) @ cost of slowing code?

thanks.

implementing iterators wrapper around c array trivial -- return pointers first, , one-past-the-last, element begin , end respectively, , adding non-virtual methods pod class won't slow down of anything. accessing array via these methods won't slower using array index lookups, , can faster in contexts. , if don't use them, code won't run slower.

as advantage, in c++11 if have begin , end method, std::begin , std::end find it, , for( auto x: container ) { /* code */ } work on type.

as seems x/y problem, suspect 1 of problems shouldn't using ntuple class @ all. std::vector<double> thin wrapper around c-style array written. pass without cost of copying it, std::vector<double> const&.

as pedantic aside, stl refers library template component of std derived. differs std library in few ways.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -