vector

Memset on vector C++

Is there any equivalent function of memset for vectors in C++. (Not clear() or erase() method, I want to retain the size of vector, I just want to initialize all the values) ...

c++ vector random shuffle part of it

Whats the best way to shuffle a certain percentage of elements in a vector. Say I want 10% or 90% of the vector shuffled. Not necessarily the first 10% but just 10% across the board. TIA ...

Need a vector that derives from a vector.

Hi, Consider this simple code: class A { }; class V1: vector<A *>{ // my nice functions }; if I have a instance of V1, then any object derived from A can be inserted into the vector, ok here. Now, lets say I have two simple classes called B and C both derives from A; if I have a instance of V1, then both pointers of B and C can...

vector and garbage collector

I'm running a java program that uses many vectors. I'm afraid my use of them is causing the garbage collector not to work. I have many threads that do: vec.addAll(<collection>); and other threads that do: vec.remove(0); I have printouts that show the vector is empty from time to time but I was wondering if the memory is actually f...

How do I generate the following matrix and vector from the given input data in MATLAB?

Suppose I have the inputs data = [1 2 3 4 5 6 7 8 9 10] and num = 4. I want to use these to generate the following: i = [1 2 3 4 5 6; 2 3 4 5 6 7; 3 4 5 6 7 8; 4 5 6 7 8 9] o = [5 6 7 8 9 10] which is based on the following logic: length of data = 10 num = 4 10 - 4 = 6 i = [first 6; second 6;... num times] o = [last 6] What is the ...

split a string vector [R]

I have the following vector: tmp3 <- c("1500 2", "1500 1", "1510 2", "1510 1", "1520 2", "1520 1", "1530 2", "1530 1", "1540 2", "1540 1") I would like to just retain the second number in each of the atoms of this vector so it would read: c(2, 1,2,1,2,1,2,1,2,1). ...

sort using boost::bind

bool pred(int k, int l, int num1, int num2) { return (num1 < num2); } int main() { vector <int> nums; for (int i=50; i > 0; --i) { nums.push_back(i); } std::sort (nums.begin(), nums.end(), boost::bind(&pred, 5, 45)); } I am a boost newbie. I was learning to use boost::bind and I wanted to sort a vector of intege...

Convert std::vector<char*> to a c-style argument vector arv

I would like to prepare an old-school argument vector (argv) to use within the function int execve(const char *filename, char *const argv[],char *const envp[]); I tried it with the stl::vector class: std::string arguments = std::string("arg1"); std::vector<char*> argv; char argument[128]; strcpy(argument, arguments.c_str()...

Declaration with no type...

I am confused. I do this: #include <vector> // List iteration typedef vector<registeredObject>::iterator iterator; typedef vector<registeredObject>::const_iterator const_iterator; vector<registeredObject>::iterator begin(void); vector<registeredObject>::const_iterator begin(void) const; vector<registeredObject>::iterator end(void); ve...

C++ vector to pointer of pointers

Is there a way to convert a vector to a pointer to a pointer (ptr-to-ptr). Background: I have an arbitrary length set of data stored in a vector. But I have a library of algorithms that accept ptr-to-ptr (for image array access). I need to get the data from my vector to a ptr-to-ptr. How is that possible? ...

Converting vector-contoured regions (borders) to a raster map (pixel grid)

I have a map that is cut up into a number of regions by borders (contours) like countries on a world map. Each region has a certain surface-cover class S (e.g. 0 for water, 0.03 for grass...). The borders are defined by: what value of S is on either side of it (0.03 on one side, 0.0 on the other, in the example below) how many points t...

stl vector and c++: how to .resize without a default constructor?

how could I tell STL, specifically for the method resize() in vector, to initialize objects with a constructor other than default, and with which parameters? I mean: class something { int a; something (int value); } std::vector<something> many_things; many_things.resize (20); more generally, how could I force STL to use my ...

Erasing a vector element by key

ive defined the following and filled it with elements: vector <vector<double> > my_vector; but i want a delete an element with a specific key... my_vector.erase(int(specific_key)); but it doesnt allow me. how would i properly dispose of the elements assigned to that key properly? ...

Easy Trig - Move an object in a position

I know this is quite easy trigonomety, however I was never introducted to vectors etc, and I'm at a loss understanding how this works. Given an object at point XY, and a direction N, how do you move that object in that direction? Also, given am object at point XY, and a destination at point XY, how do you move an object towards the des...

What is wrong with this c++ typedef?

This is a piece of my code, I have more class like MathStudent, ArtStudent, etc. which inherits Student class. When I tried to compile, it says "forbids declaration of `vector' with no type," what is the problem here? thanks class Student { public: typedef vector<Student> Friends; // something wrong here? virtual unsigned int ...

How to cast rays given an arbitrary camera?

I'm writing a ray tracer (using left-handed coordinates, if that makes a difference). It's for the sake of teaching myself the principles, so I'm not using OpenGL or complex features like depth of field (yet). My camera can have an arbitrary position and orientation; I indicate them by way of three vectors, location, look_at, and sky, wh...

Howto create combinations of several vectors without hardcoding loops in C++?

I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A Vector3_elements = C,G,T ..... up to ... VectorK_elements = ... #Note also that the member of each vector is always 3. What I want to do is to create all combination of elements in Vector1 through out VectorK. Hence in the end we hope to get t...

Boost Multi-Index : Composite key of vector and int for hashed indices

Hi, as I've just learned in in my other question, I could use a composite_key for a struct, which has a std::vector and an integer. Now my question is: Can I use this somehow to work with hashed_indecies? Here an example similar to THIS: struct unique_property { //the pair of int and std::vector<int> shall be unique int my_int; ...

Wrapping dynamic array into STL/Boost container?

I need to wrap a dynamically allocated array(from a = new double[100] for example) into std::vector(preferably) without copying the array. This restriction is imposed by that the array I want to wrap is mmaped from a file, so just doing vector(a, a+size) will double the memory usage. Is any tricks to do that? ...

sort vector by more than 1 field

How do I sort the below code by name, age and score... all three fields #include <string> #include <vector> #include <algorithm> struct student_t { std::string name; int age, score; }; bool by_more_than_1_field( student_t const &lhs, student_t const &rhs ) { // sort by name, age and score } int main() { ...