vector

Deleting a element from a vector of pointers in C++.

I remember hearing that the following code is not C++ compliant and was hoping someone with much more C++ legalese than me would be able to confirm or deny it. std::vector<int*> intList; intList.push_back(new int(2)); intList.push_back(new int(10)); intList.push_back(new int(17)); for(std::vector<int*>::iterator i = intList.begin(); i ...

Are vectors more rigorous at checking out of bounds than heap arrays?

How rigorous is the bounds checking on vectors compared to heap arrays? How exactly is it checking bounds and how does that compare with how a heap array is checked? ...

STL vector performance

STL vector class stores a copy of the object using copy constructor each time I call push_back. Wouldn't it slow down the program? I can have a custom linkedlist kind of class which deals with pointers to objects. Though it would not have some benefits of STL but still should be faster. See this code below: #include <vector> #include ...

Initialization of a vector of vectors?

Is there a way to initialize a vector of vectors in the same ,quick, manner as you initialize a matrix? typedef int type; type matrix[2][2]= { {1,0},{0,1} }; vector<vector<type> > vectorMatrix; //??? ...

C++: How to clean up a vector/map properly

Hi, If I have a vector<string*> *vect or a map<pair<string*, int*>, string*> *map, how to clean up everything (including all object the vector/map contains)? (Everything (vector, map, contents, string, ints) is allocated with new) Is delete vect; delete map; enough? ...

vector holding read-only matrices?

I want to use a vector to hold read-only integer-matrices of the size 5x5 vector<const int[5][5]> startingPieces; But this declaration causes a bunch of weird errors I've never ever seen before. error C2535: 'const int (*std::allocator<_Ty>::address(const int (&)[5][5]) const)[5][5]' : member function already defined or declared 1> ...

Create and initialise an array of vectors in one go

To create an array of strings this works: std::string array[] = { "first", "second", : "last" }; If I try to do the same with vectors it doesn't work: std::vector<int> array[] = { {1, 2}, {3, 4, 5} : {9} }; I get "non-aggregates cannot be initialized with initializer list". What is the correct synta...

Draw Lines Over a Circle

There's a line A-B and C at the center between A and B. It forms a circle as in the figure. If we assume A-B line as a diameter of the circle and then C is it's center. My problem is I have no idea how to draw another three lines (in blue) each 45 degree away from AC or AB. No, this is not a homework, it's part of my complex geometry in ...

is std::vector same as array[number]?

Possible Duplicate: Are std::vector elements guaranteed to be contiguous? does std::vector always contain the data in sequential memory addresses as array[number]? ...

Modify in place the elements of a vector

The following doesn't work as desired (print 2) because, I guess, the nodes are passed by value even though the vector is passed by reference. How could I fix it? #include <iostream> using std::cout; using std::endl; #include <vector> using std::vector; class Node{ public: int value; Node(int); void createC...

Does STL and vector provide sort option?

Hi, Does STL and Vector provide the default sorting option?. ...

dereferencing in a vector of pointers to objects

I'm trying to access the object (called a Vector) pointed to by a pointer held in a vector container, but I can't seem to get to it. Here are the important code snippets: int main{ Vector<double>* test = new Vector<double>(randvec<double>()); test->save(); cout << Element::vectors[0]; return 0; } Where Vector is a templ...

Strange behaviour with std::vector

Hi, consider this segment of codes: std::vector<int> vecList; ...populate 3 elements into vecList... if (!vecList.empty()) { std::cout << "List count = " << vecList.size() << std::endl; if (vecList.empty()) { std::cout << "List is empty" << std::endl; } } my printout is: List count = 3 List is empty ...

Is it safe to pass a vector as an array?

Say I have a function: void someFunc(int *x,int count); which is out of my control, so I can't write it to accept iterators. Is it safe to call it like so (regardless of the specific STL implementation): vector<int> v; /* ... */ someFunc(&v[0],v.size()); Obviously, one counter example is vector<bool>. How about any other type? (as...

vector of double[2] error

...

c++ vector as a parameter Help

I wrote a function to take in a vector, a int position and a int value void add(vector<int>& pro, int pos, int val){ pro[pos] += val; while(pro[pos] > 9){ int carry = pro[pos]/10; pro[pos] %= 10; pos++; pro[pos] += carry; }//while }//function add lets say i have vector<int> list1,list2,pro...

C++ - STL vector question

Hello! Is there any way to make std::vector faster on reserving + resizing? I would like to achieve the performance which would be somewhat equivalent to plain C arrays. See the following code snippets: TEST(test, vector1) { for (int i = 0; i < 50; ++i) { std::vector<int> a; a.reserve(10000000); a.resize(10000000...

Need help deciphering gprof output

I am pretty sure this has something to do with a vector of void function pointers, but I can't really make anything out of it. Can someone break this down for me? __gnu_cxx::__normal_iterator<unsigned long long const*, std::vector<unsigned long long, std::allocator<unsigned long long> > >::difference_type __gnu_cxx::operator-<unsigned ...

Ruby SIMD & SSE

I'm wondering if there is a way to extend ruby Array type to do SIMD & SSE vector calculation. I mean implement in an low-level language to be used in ruby programs to number crunching tasks. ...

Private class in a Vector used publically

In Java, what happens when you reference a private class in a vector from outside the class? Example: public class A { private class B {} public Vector<B> vector = new Vector<B>(); public A() { vector.add(new B()); } } public class C { public C() { A a = new A(); a.vector.get(0); // <- What does this return? }...