I'm making a simple crime sim game.
Throughout it I keep doing the same thing over and over:
// vector<Drug*> drugSack;
for (unsigned int i = 0; i < this->drugSack.size(); i++)
this->sell(drugSack[i]);
Just one example. I hate having all these for loops all over the place omg QQ, anyway to do something like:
drugSack->D...
I'm adding two different elements to both std::list and std::set and I want the std::list to be sorted with the same order as of std::set. one way I tried is when the element is added to std::set, find that element then get the index of that element using std::distance(begin, found) and then insert the element to that index in std::list....
I understand the semantics of the 2 operations ,
assign- erases before replacing with supplied values.
insert - inserts values at specified location(allocates new memory if necessary).
Apart from this is there any reason to preffer one over the other?
Or to put it another way, is there any reason to use assign instead of insert.
...
I was going through the auto_ptr documentation on this link auto_ptr
There is something which i could not fully understand why is it done. In the interface section there are two declarations for its copy constructor
1)
auto_ptr(auto_ptr<X>&) throw ();
2)
template <class Y>
auto_ptr(auto_ptr<Y>&) throw();
What purpose i...
auto_ptr_ref documentation here says this
This is an instrumental class to allow certain conversions that allow auto_ptr objects to be passed to and returned from functions.
Can somebody explain how auto_ptr_ref helps in achieving this. I just want to understand the auto_ptr class and its internals
...
In a programming task, I'm trying to ensure a particular vector contains only unique items. With primitive types, the operation is as simple as:
vector<int> lala;
lala.push_back(1);
lala.push_back(99);
lala.push_back(3);
lala.push_back(99);
sort(lala.begin(), lala.end()); // lala: 1, 3, 99, 99
lala.erase(unique(lala.begin(), lala.end()...
I'm on Linux; looking at the STL headers; they're really really complicated.
Is there, somewhere, a smaller version of STL that has the core features of the STL, but is actually readable?
Thanks!
...
I am having a problem using const reverse iterators on non-const containers with gcc. Well, only certain versions of gcc.
#include <vector>
#include <iostream>
using namespace std;
int main() {
const char v0[4] = "abc";
vector<char> v(v0, v0 + 3);
// This block works fine
vector<char>::const_iterator i;
for (i = ...
I want to pose a seemingly simple question that i can't find the answer nowhere.
Is there a FAST modern algorithm for file input and/or output that can be compiled with all standard compliant C++ compilers and works for all operating systems without the requirement of external libraries ?
i have found that the fastest way is to use mem...
Hello,
I developed a scripting engine that has many builtin functions, so far to call any function code just went into a if .. else if .. else if wall checking the name but I would like to develop a more efficient solution.
Shoul I use a hashmap with strings as keys and pointers as values. How could I do it by using an STL map?
EDIT:
...
I am working on a software where i have to create a graph (using boost::adjacency_list).
The incremental insertion of vertices takes an extremely long time.
Until now, i hadn't worked on the issue, because the use of STLport made this problem go away.
I have now migrated my work to Visual Studio 2008, but can't take the time to go on us...
I'm trying to create a priority queue with a custom comparator:
std::priority_queue<int, std::vector<int>, MyComparator> pq;
My problem is that MyComparator has a method that stores additional state. Because MyComparator is copied to the priority queue (as far as I can tell), there's no way for me to call this method on the MyComparat...
The following line of code compiles just fine and behaves:
list<const int *> int_pointers; // (1)
The following two lines do not:
typedef int * IntPtr;
list<const IntPtr> int_pointers; // (2)
I get the exact same compile errors for
list<int * const> int_pointers; // (3)
I'm well aware that the last line is not legal since the...
In C++, is it safe to use an std::map or std::vector concurrently in different threads if you are NOT inserting, just doing .find() operations on it?
...
is it possible to iterate through until the end of list in main() function using the const_iterator? I tried using iter->end() but i can't figure it out.
#include <list>
#include <string>
using std::list;
using std::string;
class list_return
{
public:
list <string>::const_iterator get_list()
{
_list.push_back("1");
_list.push_back("2")...
Consider the class:
MyClass {
int varA;
int varB;
};
I have a vector of pointers to MyClass objects:
std::vector<MyClass*> Vec;
I want to sort the vector according to varA or varB using the same sort function, i.e. :
bool SortFunction(const MyClass* obj1, const MyClass* obj2, const short type) {
if( type == VARA_ID )
...
Hello, I am trying to compile some C++ code as a static library to use on the iPhone. If I compile things for the simulator (i386 architecture), everything compiles just peachy, but when I switch the architecture to arm, I get all these include errors, seemingly within the iPhone SDK STL headers. Any idea what's going on?
First of the e...
class Help
{
public:
Help();
~Help();
typedef std::set<string> Terms;
typedef std::map<string, std::pair<int,Terms> > TermMap;
typedef std::multimap<int, string, greater<int> > TermsMap;
private:
TermMap terms;
TermsMap termsMap;
};
How can we find the memory used (in bytes...
Having spent quite some time developping in C#, I noticed that if you declare an abstract class for the purpose of using it as an interface you cannot instantiate a vector of this abstract class to store instances of the children classes.
#pragma once
#include <iostream>
#include <vector>
using namespace std;
class IFunnyInterface
{
p...
I'm trying to learn C++ and right now I'm writing a program that needs to output a list of pairs of integers.
What is the best way to handle this? I don't have the boost library available on our linux computers at school, so I don't believe I can use boost::tuple.
Any suggestions?
...