vector

How to create an empty R vector to add new items

Hi, I want to use R in Python, as provided by the module Rpy2. I notice that R has very convenient [] operations by which you can extract the specific columns or lines, how could I achieve such a function by python scripts? My idea is to create a R vector and add those wanted elements into this vecotr so that the final vector is the same...

Speeding up Autodesk Maya's Vector Renderer

I have a scene composed mainly of NURBs, which I want to render in the Vector renderer strictly for the look it gives me--not the vector it delivers. I first convert the NURBs to a very low-res polygon mesh (by control point), which gives me a very light scene. However, my renders are taking a really, really long time (like 5 minutes f...

Effective way to calculate the up vector for gluLookAt which points up the y-axis the most?

Hello, I need to create an up vector for when the camera looks at any angle (except directly down or up because the up vector would be perpendicular to the y-axis). The up vector has to be perpendicular to the line of sight of-course. When the line of sight isn't along the y-axis, you can imagine a circle around the eye and the line of ...

Number of permissible active iterators into a vector

For example is the following valid? std::vector<int> vec(5, 0); std::vector<int>::const_iterator it1(vec.begin()); std::vector<int>::const_iterator it2(vec.begin()); //Use it1 and it2 like they don't know about each other. Is there a special name for a container that permits multiple active iterators? ...

+= on a vector without boost

Is there any way to use the += operator with a vector without using boost or using a derivated class? Eg. somevector += 1, 2, 3, 4, 5, 6, 7; would actually be somevector.push_back(1); somevector.push_back(2); somevector.push_back(3); etc. ...

Vector sum in C++ design strategy

Possible Duplicate: sum of elements in a std::vector I want to sum the items of a std::vector For example std::vector<int > MYvec; /*some push backs*/ int x=sum(MYVec); //it should give sum of all the items in the vector How to write sum function? I have tried this int sum(const std::vector<int> &Vec) { int res...

Filling std vector

Hello, I can't understand why does vector empty after it's filling. The code is: bool fillArray (vector<int> &array) { string temp; getline(cin, temp); if (temp == "-1") return false else return true; int res = atoi(temp.c_str()); array.push_back(res); } void showArray(const vector<int>...

How do I code and pass a (reference to a std::vector)?

I can't seem to get this right. class Tree { Node* root; vector& dict; } class Node { vector& dict; char* cargo; Node left; Node right; } I want each instance of Tree to have it's own dict, and I want it to pass a reference to the dict to the node constructor, which would recursively pass the refere...

C++ memory management for a vector with variable length items

Take a variable length struct (if this were a real program, an int array would be better): #include <vector> struct list_of_numbers(){ int length; int *numbers; //length elements. }; typedef std::vector<list_of_numbers> list_nums; //just a writing shortcut (...) And build a vector out of it: list_nums lst(10); //make 10 lists. l...

C++ vectors of classes with constructors.

//Using g++ and ubuntu. #include <vector> using namespace std; Define a class: class foo(){ (...) foo(int arg1, double arg2); } Constructor: foo::foo(int arg1, double arg2){ (...) //arrays whose length depend upon arg1 and arg2 } I would like to do something like this: vector<foo> bar(10); //error: no matching function for cal...

Serialise and deserialise vector in binary

Hi all, I am having problems trying to serialise a vector (std::vector) into a binary format and then correctly deserialise it and be able to read the data. This is my first time using a binary format (I was using ASCII but that has become too hard to use now) so I am starting simple with just a vector of ints. Whenever I read the dat...

vector of vector

for example we have following code pragment #include <iostream> #include <ostream> #include <vector> using namespace std; int main() { vector<vector<int>>v; return 0; } i have question as i see this form v.push_back(11) does not work what will be correct? ...

java vector to arraylist

Is there any way to copy or convert a vector to arraylist in Java? ...

Reverse iterating with 2 loops?

Basically I want to reverse iterate through 2 std::vectors. a layer has a vector of shapes. usually I could do something like this: for(int i = 0; i < layers.size(); ++i) { for(int j = 0; j < layers[i].shapes.size(); ++j) { layers[i].shapes[j].dosomething(); } } However right now I need to reverse iterate through the v...

What's faster: new Vector.<T> OR Vector.<T>.splice(0, Vector.<T>.length)?

What gives the best performance? (edited to include another option) var myVec:Vector.<Number> = new Vector.<Number>(); for (...) // Do stuff - example: myVec.push(Math.random()); // Need to empty and repopulate vector myVec.splice(0, myVec.length); // OR myVec = new Vector.<Number>(); // OR myVec.length = 0; ...

vector<T>::iterator - invalid?

Possible Duplicate: g++ is not a type error The following does not compile: 1 template<typename T> 2 void foo(std::vector<T>::iterator & i) 3 { 4 } On Visual Studio, I get the following errors: >(2) error C2065: 'i' : undeclared identifier >(4) warning C4346: 'std::vector<_Tp>::iterator' : dependent name is ...

vector with constant size

I am looking for a C++ data type similar to std::vector but without the overhead related to dynamic resizing. The size of the container will remain constant over its lifetime. I considered using boost::array, however, that is not appropriate because it requires the size of the array to be known at compile time, which is not the case in m...

Atomically std::vector::push_back() and return index

I need to create a function which appends a value to a vector and returns the index of the value that was just appended. Example: int append(std::vector<int>& numbers, int number){ int retval = numbers.size(); // what if some other thread calls push_back(number) in between these calls? numbers.push_back(number); return retval; ...

vector of pointer to object - how to avoid memory leak?

Hi gentlemen, How do we ususaly deal with a vector whose elements are pointers to object? My specific question is the comment at the end of the code supplied below. Thanks. class A { public: virtual int play() = 0 ; }; class B : public A { public: int play() {cout << "play in B " << endl;}; }; class C : public A { public: int...

check if a std::vector contains a certain object?

Possible Duplicate: How to find an item in a std::vector? Is there something in algorithm.h which allows you to check if a std:: container contains something? Or a way to make one ex: if(a.x == b.x && a.y == b.y) return true; return false; can this only be done with std::map since it uses keys? Thanks ...