vector

C++ Deallocating objects stored in a vector

I have a class that creates a vector of objects. In the deconstructor for this class I'm trying to deallocate the memory assigned to the objects. I'm trying to do this by just looping through the vector. So, if the vector is called maps I'm doing: Building::~Building() { int i; for (i=0; i<maps.size(); i++) { delete[] &m...

iOS Advanced Gestures: Getting Swipe Direction Vector

Looking through the documentation, it seems that the new advanced gestures API doesn't determine the direction of a swipe beyond the basic { left, right, up, down }. I need the start point of the swipe and the direction. Is there anyway to retrieve this other than coding my own advanced gesture library from scratch out the basic gestur...

Sending a Vector of objects over a network

Okay, so I'm writing a test program to send a vector of objects from server to client. -Server- import java.net.*; import java.util.Vector; import java.io.*; public class TestServer{ public static void main(String[] args) throws IOException { Vector<Obj> obj = new Vector<Obj>(); obj.add(new Obj(5)); obj.ad...

C++ vector max_size();

On 32 bit System. std::vector<char>::max_size() returns 232-1, size of char 1 byte std::vector<int>::max_size() returns 230-1, size of int 4 byte std::vector<double>::max_size() returns 229-1, size of double 8 byte can anyone tell me max_size() depends on what? and what will be the return value of max_size() if it runs on 64 bit ...

Fast vector math in Clojure / Incanter

I'm currently looking into Clojure and Incanter as an alternative to R. (Not that I dislike R, but it just interesting to try out new languages.) I like Incanter and find the syntax appealing, but vectorized operations are quite slow as compared e.g. to R or Python. As an example I wanted to get the first order difference of a vector u...

List to integer or double in R

I have a list of about 1000 single integers. I need to be able to do some mathematical computations, but they're stuck in list or character form. How can I switch them so they're usable? sample data : y [[1]] [1] "7" "3" "1" "6" "7" "1" "7" "6" "5" "3" "1" "3" "3" "0" "6" "2" "4" "9" [19] "1" "9" "2" "2" "5" "1" "1" "9" "6" "7" "4...

Network sent Vector only updates once in client?

Okay, so I'm trying to send a vector of objects from server to client. the clients take control of one object from the vector and send it's x and y to the server vector. Now the server is running fine from what I can tell. things are updating in real time, but the client only seems to update right once - when it starts. this is the cli...

Count number of vector values in range with R

In R, if you test a condition on a vector instead of a scalar, it will return a vector containing the result of the comparison for each value in the vector. For example... > v <- c(1,2,3,4,5) > v > 2 [1] FALSE FALSE TRUE TRUE TRUE In this way, I can determine the number of elements in a vector that are above or below a certain numb...

Using operator[] on empty std::vector

I was advised a while ago that is was common place to use std::vector as exception safe dynamic array in c++ rather than allocating raw arrays... for example { std::vector<char> scoped_array (size); char* pointer = &scoped_array[0]; //do work } // exception safe deallocation I have used this convention multiple times wit...

Vector insert crashes program.

Can anyone tell me why this crashes my program? It's suppose to make it so order has all the elements in the t vector situated by (y + height). Edit: crashes on the lines with "insert" in them. void createDrawOrder(vector<Thing*> t, vector<int> *order) { int min = t[0]->y + t[0]->height; int max = t[0]->y + t[0]->heigh...

Vector push_back Access Violation

This is probably a silly error, but it's driving me nuts trying to fix it. I have a struct: struct MarkerData { int pattId; unsigned short boneId; Ogre::Matrix4 transToBone; Ogre::Vector3 translation; Ogre::Quaternion orientation; MarkerData(int p_id, unsigned short b_id, Ogre::Matrix4 trans) { pattId = p_id; boneId = b_i...

std::map::erase infinite loop

I have a map of a vector of char's and a vector of strings. Every so often, if I've seen the vector of characters before, I'd like to add a string to my vector of strings. Below is my code to do that. map<vector<char>, vector<string>>::iterator myIter = mMyMap.find(vChars); if(myIter != mMyMap.end()) { vector<string> vStrings = my...

template vector

Hi All, I'm trying to implement a function that allows me to make a call like this // veca is a vector of tuples in my case columnViewOfTuple<0>(veca); I implemented such function as follows template<int N> struct myfunction { template<typename T, typename R> std::vector<R> operator() (T& container) { std::vector<...

vector template conflicting declaration

I'm trying to implement a function that allows me to make a call like this // vec5 is a vector of tuples in my case // some code that to declare and fill vec5 columnViewOfTuple<0>(vec5); I implemented such function as follows template<int N> struct myfunction { template<typename T, typename R> std::vector<R> opera...

Java: Change String[][] Dynamically

I have this code: newArray = new String[][]{{"Me","123"},{"You","321"},{"He","221"}}; And I want to do this dynamically. Add more elements, things like it. How do I do this? PS: Without using Vector, just using String[][]; ...

4 Element Vector (3D Math)

Why is there a W term in a lot of 3D API's Vector class (i.e. Vector4(x, y, z, w) ) ? Are there math operations that absolutely require the W term? ...

Insert into 2D vector

Could you do the insert operation in one line along with allocating memory for internal vector? vector <vector<int>> myvector; int a[] = {0, 1, 2, 3, 4}; for (int index = 0; index < 2; index++) { myvector.push_back(vector<int>()); //allocate memory for internal vector myvector[index].insert(myvector[index].begin(),...

Passing Pointer of vector of pointers... no no?

New to C++ and its giving me a hissy fit. The actual code is on a different computer and I can't copy it, so I'll do the best I can with pseudo code. My endgame is to have a vector [of pointers] that can be accessed by several different objects. The way I attempted to go about this is have the original class that contains the vector to...

hpp files && implememtning a class extending vector

hi, i have 2 questions. does any one know what an hpp file is? why would someone do that ? i am trying to implement a class that extends vecotr but i want to use all thee riginal functinos and add on actions for each functin. so i wrote: #include <iostream> #include <vector> #ifndef _MY_PERSONAL_VECTOR #define _MY_PERSONAL_VECTOR ...

Checking whether a vector is empty

Suppose I have a std::vector say Vector Now after performing some operations on the vector(either insertion or deletion) I want to check if the vector is empty and on the basis of that I want to perform some operations. Which approach is better Approach 1 if (Vector.size() == 0){ /* operations */ } Approach 2 if (Vector.empty()) {...