vector

Is it possible to define a generic type Vector in Actionsctipt 3?

Hi i need to make a VectorIterator, so i need to accept a Vector with any type. I am currently trying to define the type as * like so: var collection:Vector.<*> = new Vector<*>() But the compiler is complaining that the type "is not a compile time constant". i know a bug exists with the Vector class where the error reporting, reports ...

vector resizing - portable way to detect.

I have a vector that I am loading with a know amount of elements (N). The processing dynamically creates new elements, which are appended to the vector. I am expecting about 2 * N additional elements to be created, so I resize the vector to 3 * N. If the additional elements exceed that, I would like a program abort, rather than ...

why does printf show a 0 for vector size when cout shows the correct size?

I don't get why I get 0 when I use printf and %d to get the size of my vector: vector<long long> sieve; int size; ... //add stuff to vector ... size = sieve.size(); printf("printf sieve size: %d \n", size); //prints "printf sieve size: 0" std::cout << "cout sieve size: "; std::cout << size; std::cout << " \n "; //prints "cout sieve size...

Overloading operator << - C++

Background I have a container class which uses vector<std::string> internally. I have provided a method AddChar(std::string) to this wrapper class which does a *push_back()* to the internal vector. In my code, I have to add multiple items to the container some time. For that I have to use container.AddChar("First"); container.AddChar(...

expand size of vector passed as memory

I am passing my vector to a function that expects a c array. It returns the amount of data it filled (similar to fread). Is there a way i can tell my vector to change its size to include the amount that function has passed in? of course i make sure the vector has the capacity() to hold that amount of data. ...

disable vector fill value on resize? c++

I'm in a situation where i must use a c style function that returns the len copied. I decided i should resize to max, then resize to the length returned http://stackoverflow.com/questions/605539/expand-size-of-vector-passed-as-memory I know resize sets the value to fillValue (always 0?). So theres going to be pointless initialization (h...

How to draw a table with C#?

I need to draw a table of data into a vector image with C#. I'm looking a library or component that helps me to draw the table without having to care about its layout myself. All I'd like to care about is what data belongs into which cell. I already know of some libraries that allow me to create vector images with C# (e.g. SharpVector...

Clean vector every loop iteration. What is the most memory efficient way?

Hi, I have a question about the std::vector. I have a very memory intensive algorithm where I forsee that predicting vector sizes and reserving enough memory for the vectors in advance will help me a lot with reducing memory usage. Which of the following is better: for ( ... ) { std::vector<Type> my_vector; my_vector.reserve(stuff...

C++: Rotating a vector around a certain point

Hi All, I have a very simple question. I am trying to rotate a vector around a certain point on the vector(in C++): 1 2 3 4 5 6 7 8 9 rotated around the point (1,1) (which is the "5") 90 degrees would result in: 7 4 1 8 5 2 9 6 3 Right now I am using: x = (x * cos(90)) - (y * sin(90)) y =(y * cos(90)) + (x * sin(90)) But I do...

More efficient way to reuse vector as array in winsock?

Hi, I'm currently using vectors as c-style arrays to send and recieve data through Winsock. I have a std::vector and I'm using that as my 'byte array'. The problem is, I'm using two vectors, one for each send, and one for each recv, but what I'm doing seems to be fairly inefficient. Example: std::string EndBody("\r\n.\r\n"); std::fil...

What's the cleanest way to walk and unwalk a std::vector using iterators?

I have a situation where I'm marching through a vector, doing things: std::vector::iterator iter = my_list.begin(); for ( ; iter != my_list.end(); ++iter ) { if ( iter->doStuff() ) // returns true if successful, false o/w { // Keep going... } else { for ( ; iter != m_list.begin(); --iter ) // ...This won't work......

How to copy the contents of std::vector to c-style static array,safely ?

I need to manipulate data in fixed array involving mid insertion. Rather than using memcpy,etc. I want to use vector. I have problem when I want to copy the vector elements back to the c-style array. Here's the code: void tryvector() { using namespace std; const int MAX_SIZE=16; BYTE myarr[MAX_SIZE]={0xb0,0x45,0x47,0xba,0x11...

create pdf with long lines, fit to pagewidth without wordwrap

i'd like to create a large pdf (not typical page size) with long lines, max ~1000 characters / line, where the page size and font are such that no lines need to wrap. the intention is not for the text in this document to be readable when the full page is viewed on any reasonably-sized monitor -- instead the reader can zoom to individual...

Remove the common entities from two vector?

say I have vector<class1a>,vector<class1b> how to remove the common entities from both of them I have defined ==operator for the class1 objects class1a,class1b ...

looping to make upper case characters for a vector<struct> element

Upon debugging i had thought i did it right. But it was only the first member as the first element in the vector that was corrected. while ( !inFile->eof() ) { getline( *inFile, str1, ',' ); sStruct.str1 = str1; getline( *inFile, str2, ',' ); sStruct.str2 = str2; getline( *inFile, str3, ',' ); sStruct.str3 ...

How would you remove elements of a std::vector based on some property of the elements?

If for instance you have a std::vector<MyClass>, where MyClass has a public method: bool isTiredOfLife(), how do you remove the elements that return true? ...

Howto Create Map of Vector From Sorted Data

Dear all, I have the following data as input (sorted by first column): foo 1 2 foo 3 3 bar 10 11 I want to create a Map of Vector with first column as key of the map such that we have: foo = {1,2,3,3} bar = {10,11} But why my code below doesn't work as expected? #include <vector> #include <map> #include <iostream> ...

Alternative to vector<bool>

As (hopefully) we all know, vector<bool> is totally broken and can't be treated as a c array. What is the best way to get this functionality? So far, the ideas I have thought of are: Use a vector<char> instead, or Use a wrapper class and have vector<bool_wrapper> How do you guys handle this problem? I need the c_array() functionality...

C++ STL Vectors: Get iterator from index?

So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need to copy just a chunk of the vector. It looks like vector.insert(pos, first, last) is the function I want... except I only have first and last as ints. Is there any nice way I can get an iterator to these values? ...

How is dynamic memory managed in std::vector?

How does std::vector implement the management of the changing number of elements: Does it use realloc() function, or does it use a linked list? Thanks. ...