I am considering to put one of the following as a reference on my desk (as I am sick and tired to google every time I have a STL question):
The C++ Standard Library: A Tutorial and Reference
STL Tutorial and Reference Guide: C++ Programming with the Standard Template Library
Generic Programming and the STL: Using and Extending the C++...
Hello,
So I'm looking through some code, and I see this:
class whatever
{
public:
void SomeFunc(SomeClass& outVal)
{
outVal = m_q.front();
m_q.pop();
}
private:
std::queue<SomeClass> m_q;
};
This doesn't seem like outVal would be a valid reference any more... However, it appears to work.
I've see...
I have been following this convention thus far:
std::string line;
while(std::getline(in,line))
{
if(line.size() && line[0] =='#')
continue;
/* parse text*/
}
The obvious drawback is that comment may not begin at the first character, in the case of leading whitespace.
What is the good way to deal with this sort of a thi...
I have a network client with a request method that takes a std::streambuf*. This method is implemented by boost::iostreams::copy-ing it to a custom std::streambuf-derived class that knows how to write the data to a network API, which works great. This means I can stream a file into the request without any need to read it all into memor...
I encounter many times with code where std::vector::clear() of class member of type std::vector is called in constructor and destructor.
I don't see why it's required:
constructor - the class member of type std::vector is empty by default, so no need to call clear().
destructor - the class member of type std::vector will be destroyed...
I'm working with a low-level API that accepts a char* and numeric value to represent a string and its length, respectively. My code uses std::basic_string and calls into these methods with the appropriate translation. Unfortunately, many of these methods accept string lengths of varying size (i.e. max(unsigned char), max(short), etc......
What benefits do I get from Apache C++ standard library that I don't get from STL implementations that come with the compiler and from Boost libraries?
...
Hi,
I am porting a program to AIX which takes use of hash_map in many places.
For linux and solaris hash_map is included in _gnu_cxx package and stlport.
However, I can't find hash_map on AIX platform. Anybody know?
Btw, I have to use IBM compiler /usr/vacpp/bin/xlC.
Thanks.
...
What is the difference between the index overloaded operator and the insert method call for std::map?
ie:
some_map["x"] = 500;
vs.
some_map.insert(pair<std::string, int>("x", 500));
...
I am trying to add iostream to the legacy code and thus want to sync those two libraries.
According to this article, I should use std::ios_base::sync_with_stdio.
Now, I wonder how it is used in practice (examples please), side-effects I should be aware of.
Thx
...
Allegedly inlining std::inner_product() does NOT get inlined with gcc compiler < gcc 4.1
compilers, per the following bug .
Hence I would like to implement my own version of inner_product. Are
there existing implementation available?
Thanks
...
C++ developers, all know the basics of C++: Declarations, conditionals, loops, operators, etc.
Some of us even mastered the stuff like templates, object model, complex I/O, etc.
But what are the most hidden features or tricks or dark corners of C++/STL that even C++ fans, addicts, and experts barely know?
I am talking about a seasoned...
I'am trying to return a string from a function but it doesn't compile.
When I replace the std::string& type with int& it compiles, however I want to return additionally to the boolean a std::string how do I do this?
bool luacw_getElementContent( std::string name, std::string& content, bool fromBeginning )
{
content = "test";
retur...
Hi,
I couldn't find an answer but I am pretty sure I am not the first one looking for this.
Did anyone know / use / see an STL like container with bidirectional access iterator that has O(1) complexity for Insert/Erase/Lookup ?
Thank you.
...
So, I like vectors a lot. They're nifty and fast. But I know this thing called a valarray exists. Why would I use a valarray instead of a vector? I know valarrays have some syntactic sugar, but other than that, when are they useful?
...
I'm trying to work through ways to create a class with a std::string argument, but which also handles NULL without throwing an exception. Here's an example of the code:
class myString {
public:
myString(const std::string& str) : _str(str) {}
std::string _str;
};
int main() {
myString mystr(NULL);
printf("mystr = <%s>\n...
I would like to use different instances of an STL custom allocator class to manage different memory spaces, and then be able to specify an allocator instance to an STL container such that each container only draws from its assigned memory space. But I don't see how I can do that. I see how I can pass an allocator type into the template...
Hi,
I've been trying to make some custom exception classes for a C++ library I'm working on. These custom exceptions capture extra info, such as file,line number,etc, needed for debugging, if for some reason while testing an exception is not caught in the right place. However most people seem to recommend inheriting from the std::excepti...
I have an incoming stream of messages, and want a window that allows the user to scroll through the messages.
This is my current thinking:
Incoming messages go into single producer single consumer queue
A thread reads them out and places them into a circular buffer with a sequential id
This way I could have multiple incoming streams s...
I want to have some data cache which contains some objects which I can update over an UpdateCache function. However, I'm getting problems with a LNK2001 followed by a LNK1120.
HeaderFile.h
#ifndef headerfile_included
#define headerfile_included
#include <vector>
struct MyObject {
unsigned int A;
unsigned int B;
};
class MyClass...