vector

storing mem_fun in a standard container

Is there a way to create a vector< mem_fun_t< ReturnType, MyClass > > ? The error i'm seeing is: error C2512: 'std::mem_fun1_t<_Result,_Ty,_Arg>' : no appropriate default constructor available ...

C++ Access a member of a class from the pointer of a vector of the class

Sorry but this is really confusing me and I know the answer is staring at me in the face and I can't figure it out. Could someone take a look? Its for a Airline Reservation System school project. This function takes in the Flight Number, capacity, the count of the number of flights, and the vector containing all of the flights as argume...

Java vector help

Hi, I have just started the Java. Please let me know what this statement says class ABC{ transient Vector<int> temp[]; ABC(int max) { this.temp = new Vector [max]; } Is it creating a vector of int which size is max? I am C++ person. ...

c++ : vector addition operation

Hi, I am trying to add two Vectors below is the code snippet :- #include <iostream> #include <vector> using namespace std; int main() { unsigned int i = 0; vector <float> v1; vector <float> v2; vector <float> v3; cout << "Filling the Numbers\n"; for (i=5;i < 125 ; i = i + 5) { ...

Multiply rows of matrix by vector?

I'm optimizing a function and I want to get rid of slow for loops. I'm looking for a faster way to multiply each row of a matrix by a vector. Any ideas? EDIT: I'm not looking for a 'classical' multiplication. Eg. I have matrix that has 23 columns and 25 rows and a vector that has length of 23. In a result I want to have matrix 25x23...

A std::vector of pointers?

Here is what I'm trying to do. I have a std::vector with a certain number of elements, it can grow but not shrink. The thing is that its sort of cell based so there may not be anything at that position. Instead of creating an empty object and wasting memory, I thought of instead just NULLing that cell in the std::vector. The issue is tha...

How to erase entries from vector in C++ ?

I'm basically looping through all the entries to check whether some entries is to be erased, but seems in a wrong way: std::vector<HANDLE> myvector; for(unsigned int i = 0; i < myvector.size(); i++) { if(...) myvector.erase(myvector.begin()+i); } Anyone spot the problem in it? How to do it correctly? ...

Prettier syntax for "pointer to last element", std::vector?

I'm wondering if there is prettier syntax for this to get a normal pointer (not an iterator) to the last element in a C++ vector std::vector<int> vec; int* ptrToLastOne = &(*(vec.end() - 1)) ; // the other way I could see was int* ptrToLastOne2 = &vec[ vec.size()-1 ] ; But these are both not very nice looking! ...

Merge two STL vectors with an alternation pattern

I have two STL vectors A and B and need to merge them into a third one, where the elements should be ordered in a way, that every nth element in the output vector should be of vector B. My current code looks something like this: std::vector<int> a(10, 4); std::vector<int> b(10, 8); std::vector<int> c; static const std::size_t STEP(3); ...

std::vector is so much slower than plain arrays?

I've always thought it's the general wisdom that std::vector is "implemented as an array," blah blah blah. Today I went down and tested it, seems to be not so: Here's some test results: UseArray completed in 2.619 seconds UseVector completed in 9.284 seconds UseVectorPushBack completed in 14.669 seconds The whole thing completed in 26....

Can I detach a std::vector<char> from the data it contains?

I'm working with a function which yields some data as a std::vector<char> and another function (think of legacy APIs) which processes data and takes a const char *, size_t len. Is there any way to detach the data from the vector so that the vector can go out of scope before calling the processing function without copying the data contain...

Why use Float.floatToIntBits() in Java float comparisons?

In JBox2d, there exists the following code for Vec2.equals(): @Override public boolean equals(Object obj) { //automatically generated by Eclipse if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec2 other = (Vec2) obj; if (Float.float...

Compiler Error C2106 when trying to simulate a vector

I'm trying to write a fake vector for my class assignment, and I currently get an error in the member function pushBack. The compiler doesn't seem to like incrementing the SIZE variable which holds the number of elements in the "vector". Is there something I might need to fix? Your assistance would be highly appreciated for helping me wi...

R: Adding zeroes after old zeroes in a vector ??

Hello Imagine I have a vector with ones and zeroes I write it compactly: 1111111100001111111111110000000001111111111100101 I need to get a new vector replacing the "N" ones following the zeroes to new zeroes. For example for N = 3. 1111111100001111111111110000000001111111111100101 becomes 111111110000000111111111000000000000111111...

SVG rendering in Java using SWT - Batik too slow

I am having performance issues with Batik when I try to render SVG files using SWT. It seems like a very bloated library but the only other one I could find was SVGSalamander and it looks like it's Swing only. Is there a way to render the SVGs without converting them to a bitmap form first that's faster? It needs to be cross platform. ...

change String[] into Vector<String>

How can I convert in the quickest way String[] to Vector<String>? ...

How to return 5 topmost values from vector in R?

I have a vector and I'm able to return highest and lowest value, but how to return 5 topmost values? Is there a simple one-line solution for this? ...

How do I map a vector to a map, pushing into it repeated key values?

This is my input data: [[:a 1 2] [:a 3 4] [:a 5 6] [:b \a \b] [:b \c \d] [:b \e \f]] I would like to map this into the following: {:a [[1 2] [3 4] [5 6]] :b [[\a \b] [\c \d] [\e \f]]} This is what I have so far: (defn- build-annotation-map [annotation & m] (let [gff (first annotation) remaining (rest annotation) seq...

How can I compute the picking ray with multiple model view matrixes?

I'd like to compute the intersection between a ray and the models the user sees on the screen of my app. I'm following the OpenGL guide but I have many models in the scene that I draw independently and dynamically in a push-pop context applying a translate to the current modelview matrix (ie for each model I do a glPushMatrix, glTrans...

c++ vector of strings - issue with pointers

Hi, I'm trying to write a method that gets a vector of strings and returns a pointer to a random element. Can you please tell what is the problem with the following code? string* getRandomOption(vector<string> currOptions){ vector<string>::iterator it; it=currOptions.begin(); string* res; int nOptions = currOptions.si...