I'm trying hard to replace the global new and delete operators with XCode 3.2, GCC 4.2, libstdc++ 4.0, dynamic version.
I took the protypes directly from the header "new" and implemented them. They are pasted below.
The project is a .plugin so a dynamic lib. This plug-in MUST delegate allocation to the main application's own alloc/fre...
I have some data that is stored in a sorted vector. This vector is sorted by some key. I know the STL has an algorithm for checking if an element is in this sorted list. This means I can write something like this:
struct MyData { int key; OtherData data; };
struct MyComparator
{
bool operator()( const MyData & d1, const MyData & d2 ) ...
Why does this code result in a run-time error "vector iterator not incrementable"?
vector<string> s1, s2;
s1.push_back("joe");
s1.push_back("steve");
s1.push_back("jill");
s1.push_back("svetlana");
s2.push_back("bob");
s2.push_back("james");
s2.push_back("jill");
s2.push_back("barbara");
s2.push_back("steve");
sort(s1.begin...
Why wouldn't C++ allow something like that ?
I need to have multiple priority queues, the number of which would be determined at run time.
This fails to compile
std::vector<std::priorityqueue<Class A>>.
Is there a better approach ?
...
I want to derive from std::back_insert_iterator to create a kind of filter for a string type, say back_xml_insert_iterator, that will examine the characters passed through it looking for characters that can not be emitted "naked" into an XML stream, e.g., '"', '&', '<', '>', and '\'', and will on-the-fly insert their character entity ref...
Hi all,
Problem:
I try to deallocate memory pointed by pointer items of an STL list.
This should work fine but in my case, there can be duplicate pointers in the list and I get a double dealloc exception even though I test whether the pointer is NULL or not (see source code below).
How can I solve this problem ?
Environment:
Debian...
Having just learned that many cpp features (including the stl vector class) do not work in cu files. Even when using them in the host code.
Since I have to use a C++ class which uses STL I cannot compile my CU file which invokes the kernel. (I don't use any STL features in the CU file, but I think the include is the problem.)
I tried t...
Say I have the following:
std::vector<int> myints;
and then I have a function that returns an int vector:
std::vector<int> GiveNumbers()
{
std::vector<int> numbers;
for(int i = 0; i < 50; ++i)
{
numbers.push_back(i);
}
return numbers;
}
could I then do:
myints = GiveNumbers();
would doing this safely make it so that myints ...
i am trying to write program for evaluate Postfix-expression
code:
#include <iostream>
#include <cstring>
#include <stack>
#include <ostream>
using namespace std;
int main(int argc,char *argv[]){
char *a=argv[1];
int n=strlen(a);
stack<int>s;
for (int i=0;i<n;i++)
{
if (a[i]=='+')
s.push(s.pop()+s.pop...
Hi there,
I try to use GLM vector classes in STL containers. No big deal as long as I don't try to use <algorithm>. Most algorithms rely on the == operator which is not implemented for GLM classes.
Anyone knows an easy way to work around this? Without (re-)implementing STL algorithms :(
Kind Regards,
Florian
GLM is a great math libra...
The following example, beats me. I've been so far thinking, that when functor is being used, the object gets constructed once and the same object is used multiple times, when used with for_each algorithm and that seems to be correct.
However, even though, only one object gets constructed, but multiple objects are destroyed. Now, this b...
I have a multithreaded Windows application where one of the threads has a message pump in it. I need to send a message to that thread, passing information to it. However, one of the libraries I want to use in the worker thread requires std::string. Can I do something like the following:
typedef struct tagCOMMAND
{
std::map<std::stri...
Hello all,
I am very new to the C++ STL, so this may be trivial. I have a ostream variable with some text in it.
ostream* pout;
(*pout) << "Some Text";
Is there a way to extract the stream and store it in a string of type char*?
...
What I want to do is, in a separate namespace, define my own sort(), copy(), etc implementations that work with database tables/views/etc containers instead of in-memory std containers. If I define my own sort() that accepts my custom forward iterator, how does the compiler resolve that? Or, what do I need to do so that it will resolve...
I have an stl iterator resulting from a std::find() and wish to test whether it is the last element. One way to write this is as follows:
mine *match = someValue;
vector<mine *> Mine(someContent);
vector<mine *>::iterator itr = std::find(Mine.begin(), Mine.end(), match);
if (itr == --Mine.end()) {
doSomething;
}
But it seems to me...
I need a container that implements the following API (and need not implement anything else):
class C<T> {
C();
T& operator[](int); // must have reasonably sane time constant
// expand the container by default constructing elements in place.
void resize(int); // only way anything is added.
void clear();
C<T>::iterator be...
all the STL containers that implement resize use copies to populate the new elements even if the source of the copy is a default constructed object?
Why is it done this way?
I see no advantage and some cost.
As context, I ran across this while looking for a random access container for elements that can't be copied:
...
Hi guys,
I'm new to Objective-C, so please don't judge me too much. I was wondering: Is there an equivalent of the C++ STL pair container I can use in Objective-C?
I want to build an array that contains an NSInteger associated to an NSBool. I know I could use an array with each entry being a NSDictionary with a single key-value but I f...
Hello .
Suppose I have two containers , holding pointers to objects ,which share some of their elements .
from
http://www.cplusplus.com/reference/stl/list/erase/
it says that :
This effectively reduces the list size
by the number of elements removed,
calling each element's destructor
before.
How can I remove an object from b...
I'm trying to use std::vector<T*>::push_back with std::mem_fun and std::binder1st, but it doesnt seem to be feasible, can this be done?
I've tried to exemplify with the code below.
#include <vector>
#include <functional>
#include <iostream>
using namespace std;
struct A {
int _Foo;
virtual int AFoo() { return _Foo; }...