Hi,
I am using boost::lambda to remove subsequent whitespaces in a string, leaving only one space. I tried this program.
#include <algorithm>
#include <iostream>
#include <string>
#include <boost/lambda/lambda.hpp>
int main()
{
std::string s = "str str st st sss";
//s.erase( std::unique(s.begin(), s.end(), (boost::lamb...
We have large (100,000+ elements) ordered vectors of structs (operator < overloaded to provide ordering):
std::vector < MyType > vectorMyTypes;
std::sort(vectorMyType.begin(), vectorMyType.end());
My problem is that we're seeing performance problems when adding new elements to these vectors while preserving sort order. At the moment ...
I encountered an interesting situation today in a program where I inadvertantly assigned an unsigned integer to a std::string. The VisualStudio C++ compiler did not give any warnings or errors about it, but I happened to notice the bug when I ran the project and it gave me junk characters for my string.
This is kind of what the code lo...
Possible Duplicate:
Good book for learning the C++ standard template library?
I am having very less knowledge on templates and STL. So looking for a good for STL.
...
OK..... I've done all the reading on related questions, and a few MSDN articles, and about a day's worth of googling.
What's the current "state of the art" answer to this question:
I'm using VS 2008, C++ unmanaged code. I have a solution file with quite a few DLLs and quite a few EXEs. As long as I completely control the build enviro...
Is there a standard way to access the underlying container of stack, queue, priority_queue ?
I found a method called : _Get_container() in VS2008 implementation of stack and queue, but no one for priority_queue! I think it is not standard anyway.
Also, I know it is a silly question! where can I find official documentation of the standa...
I've made a message-only window class, and I'm trying to map HWNDs back to the objects with those handles. I'm trying to do that using a private static std::map<HWND, CMyClass*> belonging to the class, like this:
MyClass.h:
class CMyClass
{
...
private:
HWND m_hWnd;
HINSTANCE m_hInstance;
LPCSTR m_szClas...
Does the C++ Standard say I should be able to compare two default-constructed STL iterators for equality? Are default-constructed iterators equality-comparable?
I want the following, using std::list for example:
void foo(const std::list<int>::iterator iter) {
if (iter == std::list<int>::iterator()) {
// Something
}
}
...
I'm using an STL std::multiset<> as a sorted list of pointers. The sort order is determined by a property of the items being pointed to, something along the lines of this simplified example:
struct A
{
int x;
};
bool CompareAPointers(const A* lhs, const A* rhs)
{ return lhs->x < rhs->x; }
std::multiset<A*, CompareAPointers> sorted_...
Just idly curious why the compare function for stl::sort can't be a static member?
I have a small little helper class foo that is declared and defined in a header, but now I have to create a foo.cpp file for the implementation of cmp() so it isn't multiply defined.
I also have to think of a suitably decorated name so fooCmp() doesn...
Hello fellow C++ programmers.
I have, what I hope to be, a quick question about STL containers:
std::list<std::string> l;
This statement compiles fine when used in some C++ sourcefile (with the appropriate includes). But
std::list<const std::string> m;
or
std::list<std::string * const> n;
fails to compile when using gcc (gcc ver...
I have a code that looks something like this:
struct First
{
int f1;
int f2;
};
struct Second
{
First s1;
int s2;
};
std::vector < Second > secondVec;
Second sec;
sec.s1 = First();
secondVec.push_back(sec);
secondVec.push_back(sec);
std::vector < First > firstVec;
firstVec.reserve(secondVec.size());
for (std::vect...
The problem: I want to be able to FIFO queue outgoing messages. For update/deletion reasons, I also want to be able to access every message in the queue based upon an object ID.
I've currently implemented a solution where data is pushed into a deque, and an iterator to that data is kept. The iterator, keyed by an object ID, is then plac...
I have a class like this
class MyClass
{
int Identifier;
int Context;
int Data;
}
and I plan to store it in a STL container like
vector<MyClass> myVector;
but I will need to access it either by the extenal Index (using myVector[index]); and the combination of Identifier and Context which in this case I would perform a...
I'm having a really nasty problem with some code that I've written. I found someone else that had the same problem on stackoverflow and I tried the solutions but none worked for me.
I typedef several common STL types that I'm using and none of the others have any problem except when I try to typedef a map.
I get a "some_file.h:83: erro...
We've pretty much moved over to using boost::shared_ptr in all of our code, however we still have some isolated cases where we use std::auto_ptr, including singleton classes:
template < typename TYPE >
class SharedSingleton
{
public:
static TYPE& Instance()
{
if (_ptrInstance.get() == NULL)
_ptrInstance.rese...
Hello,
I want to use a different STL with g++ instead of its default libstdc++. What is the easiest way to do this?
I found -nostdinc++ flag which inhibits g++ from looking for its STL headers but this is only a compile time thing. It will still make g++ link against its own STL.
So I need to find a way to inhibit the linking.
Thanks...
Do you just base your STL container selections on the following attributes?
Searching/Updating
Insertion and
Deletion
If not, what else do you base your selections upon?
Is there any reference out there that lists how each container performs across all these different attributes?
...
Hello,
This is a follow up to an earlier question -
http://stackoverflow.com/questions/1227615/how-to-use-a-different-stl-with-g
I can now get my code to build while using a different STL. However, I still need to link -lsupc++ (along with said different STL)
I see anecodal references that -lsupc++ should be the last library on the ...
Let's say that I've got a :
#include <utility>
using namespace std;
typedef pair<int, int> my_pair;
how do I initialize a const my_pair ?
...