vector

C++ STL: How to iterate vector while requiring access to element and its index?

I frequently find myself requiring to iterate over STL vectors. While I am doing this I require access to both the vector element and its index. I used to do this as: typedef std::vector<Foo> FooVec; typedef FooVec::iterator FooVecIter; FooVec fooVec; int index = 0; for (FooVecIter i = fooVec.begin(); i != fooVec.end(); ++i, ++index) ...

crash when using stl vector at instead of operator[]

I have a method as follows (from a class than implements TBB task interface - not currently multithreading though) My problem is that two ways of accessing a vector are causing quite different behaviour - one works and the other causes the entire program to bomb out quite spectacularly (this is a plugin and normally a crash will be caugh...

Using a class with const data members in a vector

Given a class like this: class Foo { const int a; }; Is it possible to put that class in a vector? When I try, my compiler tells me it can't use the default assignment operator. I try to write my own, but googling around tells me that it's impossible to write an assignment operator for a class with const data members. One post I...

Java Stack class inherit Vector Class

By extending class Vector, Java’s designers were able to create class Stack quickly. What are the negative aspects of this use of inheritance, particularly for class Stack? Thanks a lot. ...

numpy array C api

I have a C++ function returning a std::vector and I want to use it in python, so I'm using the C numpy api: static PyObject * py_integrate(PyObject *self, PyObject *args){ ... std::vector<double> integral; cpp_function(integral); // this change integral npy_intp size = {integral.size()}; PyObject *out = PyArray_SimpleNewFromData(1, &...

Having trouble creating vectors of System::String^

So I have a regex expression to parse certain parts of a file name. I'm trying to store each part in its own vector until I use it later, but it won't let me. One error I get when I try making a vector of System::String^ is that error C3698: 'System::String ^' : cannot use this type as argument of 'new' Then, when I try just making a vec...

Vector graphics in silverlight

Hi Folks, I am new to Silverlight. Just created my first application that shows deepzoom images. Looking for some pointers how to display vector graphics in Silverligth. The graphics are all in 2D and is a series of lines (x1y1, x2y2), points (xy), basic shapes. The data is available in ASCII text files. What is the way(s) to read ...

Loading data from file to Vector structure

I'm trying to parse through fixed-width formatted file extracting x,y values of points from it, and then storing them in int[] array inside a Vector. Text file looks as follows : 0006 0015 0125 0047 0250 0131 That's the code : Vector<int[]> vc = new Vector<int[]>(); try { BufferedReader file = new BufferedR...

Euler rotation of direction vector

I have defined an object in 3D space with position, rotation and scale values (all defined as 3D vectors). It also has upwards and forwards direction vectors. When I rotate the object, I need these direction vectors to rotate with it. Assuming my up vector is (0, 1, 0) and my forwards vector is (0, 0, 1) at zero rotation, how might I ac...

Vector.erase(Iterator) causes bad memory access

Hi, I am trying to do a Z-Index reordering of videoObjects stored in a vector. The plan is to identify the videoObject which is going to be put on the first position of the vector, erase it and then insert it at the first position. Unfortunately the erase() function always causes bad memory access. Here is my code: testApp.h: vector...

Method of transforming 3D vectors with a matrix

I've been doing some reading on transforming Vector3 with matrices, and am tossing up digging deeper into the math and coding this myself versus using existing code. For whatever reason my school curriculum never included matrices, so I'm filling a gap in my knowledge. Thankfully I only need a few simple things, I think. Context is th...

c++ Sorting a vector based on values of other vector, or what's faster?

Hi, There are a couple of other posts about sorting a vector A based on values in another vector B. Most of the other answers tell to create a struct or a class to combine the values into one object and use std::sort. Though I'm curious about the performance of such solutions as I need to optimize code which implements bubble sort to ...

Can't push vector of vector of GlDouble?

I have a vector which accepts vectors of GlDouble vectors. But when I try to push one it says: Error 1 error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const std::vector<_Ty> &' c:\Users\Josh\Documents\Visual Studio 2008\Projects\Vectorizer Project\Vectorizer Project\Vectorizer Project....

vector of char array

Hi, I have the following code: static unsigned char S0_gif[] = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0f, 0x00, 0x0f, 0x00, 0x91, 0x02, .. }; It's a hex representation of a gif file. I have 500 gifs that I need to store like that so I want to use a vector to make it easier for access. Something like: vector<char[]> gifs; gif.pus...

Will destructor be called?

If I create a vector of vector of vector, if I clear the first vector, or the first vector gets deleted, will all the child vectors call the destructor and free the memory or will it cause a memory leak? Thanks ...

How large does a collection have to be for std::map<k,v> to outpace a sorted std::vector<std::pair<k,v> >?

How large does a collection have to be for std::map to outpace a sorted std::vector >? I've got a system where I need several thousand associative containers, and std::map seems to carry a lot of overhead in terms of CPU cache. I've heard somewhere that for small collections std::vector can be faster -- but I'm wondering where that line...

How to store Matrix or Vector data structure in Core Data?

I am building an iPhone application that needs to store some sort of matrix or vector data in core data. For some unknown reason, the iPhone SDK does not include any kind of matrix data structure in its foundation classes, so I built my own data structure which uses an NSMutableArray of NSMutableArrays to store the data. So far so good. ...

Access element of pointed std::vector

I have a function where I provide a pointer to a std::vector. I want to make x = to vector[element] but i'm getting compiler errors. I'm doing: void Function(std::vector<int> *input) { int a; a = *input[0]; } What is the right way to do this? Thanks ...

Using a function with variable argument strings

I was playing around a bit with functions with variable arguments, and decided to make a function to create vectors with the arguments. My function for creating an int vector worked... vector<int> makeIntVector(int numArgs, ...) { va_list listPointer; va_start(listPointer, numArgs); vector<int> made; for(int a = 0; a < n...

What are the differences between ArrayList and Vector?

What are the differences between these two data structures and where should you use each of them? ...