Hi,
I am building a DLL that another application would use. I want to store the current state of some data globally in the DLL's memory before returning from the function call so that I could reuse state on the next call to the function.
For doing this, I'm having to save some iterators. I'm using a std::stack to store all other data, ...
I have a vector of booleans. I need to set its elements from n-th to m-th to true. Is there an elegant way to do this without using a loop?
Edit: Tanks to all those who pointed out the problems with using vector<bool>. However, I was looking for a more general solution, like the one given by jalf.
...
Hi;
I was using stl::merge to put two sorted collections into one.
But my object has a natural key; and a defined addition semantic, so what I am after is a merge_and_sum that would not just merge the two collections into a single N+M length collection, but if the operator== on the object returned true, would then operator+ them.
I ha...
I have some
std::list<char> list_type
Now I have to supply contents of the list as (char *data, int length). Is there convenient way to present list contents as pointer and length? Does <vector> has such interface?
Thank you in advance.
...
Working with stl:list and stl::vector types under interrupt handlers I want to avoid malloc() calls.
The question: What is a best way to prevent malloc() calls in STL list and vector? Is it enough to create structure with predefined size and then avoid push/pop/erase calls?
Thank you in advance
...
I am using C++ hash_map to store some C-style string pairs. And all keys should be unique for this case...
My problem is a serious memory leak when stress testing this over mutliple runs.
When none of these keys in the test are not identical, there is no memory leak. But with identical keys its a different story...
The hash_map (this...
I seem to be having a problem with extracting data from a stringstream. The start of my extraction seems to be missing the first two characters.
I have something similar to the following code:
std::stringstream ss(
std::stringstream::in |
std::stringstream::out
);
bool bValid;
double dValue;
double dTime;
for( ...
I have a map that relates integers to vectors (of objects). These vectors represent a set of tasks to perform. In order to reduce the amount of copying going on while using this map and vector I've set them up to make use of pointers.
std::map<int, std::vector<MyObject *> *> myMap;
During initialization of the class that holds myMap...
I am trying to write a piece of code for fun using C++ templates.
#include <iostream>
#include <vector>
template <class Container>
std::ostream& operator<<(std::ostream& o, const Container& container)
{
typename Container::const_iterator beg = container.begin();
o << "["; // 1
while(beg != container.end())
{
o <<...
I have a string and I would like to put a reference to that string into a map.
string m_tmp;
map<pair<string, string>, string&> m;
m[pair<string, string>("Foo","Bar")]= m_tmp;
then, I change the m_tmp;
m_tmp="DFDFD";
Will the map (on all conforming platforms) still reference m_tmp with a new value?
According to the dummy program bel...
I'm trying to load binary file using fstream in the following way:
#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
using namespace std;
int main()
{
basic_fstream<uint32_t> file( "somefile.dat", ios::in|ios::binary );
vector<uint32_t> buffer;
buffer.assign( istream_iterator<uint32_t, uint32_t>...
What is the alternative if I need to use a reference, and the data I am passing I cannot change the type of, hence I cannot really store a pointer to it?
Code:
#include <map>
#include<iostream>
#include<string>
using namespace std;
int main()
{
string test;
pair<string, string> p=pair<s...
General question: Where is usually defined class, namespace.
My case:
I am only using this maps in my class implementation:
std::map<const std::pair<string, string>,const string*>
and I wonder where is it good place to put it in the class (in public:) or in the enclosing header file? I don't have namespaces
...
the C++ standard seems to make no statement regarding side-effects on capacity by either
resize(n), with n < size(), or clear().
It does make a statement about amortized cost of push_back and pop_back - O(1)
I can envision an implementation that does the usual sort of capacity changes
ala CLRS Algorithms (eg double when enlarging, ha...
I simpled the example to help with reability. Error follows the code:
#include <map>
#include<iostream>
#include<string>
using namespace std;
class A
{
public:
map<pair<string, string>, string* > m;
string str;
A():str("sdfsd")
{
m[make_pair("aa","bb")]=&str;
...
I have a join function that operates on STL strings. I want to be able to apply it to to a container like this:
getFoos(const std::multimap<std::string, std::string>& map) {
return join_values(",", map.equal_range("foo"));
In other words, find all matching keys in the collection and concatenate the values into a single string wit...
Hi,
I'd have to say I'm no expert on using the STL. Here's my problem, I have a class Called LdapClientManager which maintains a number of LDAP clients that are managed by ID. The container holding the LdapClients is declared as a member variable i.e.
typedef std::map<int, LdapClient *> LdapClientMap;
LdapClientMap _ldapClientMap;
T...
I ve been googling quite a bit for a lock-free queue in C++. I found some code and some trials - but nothing that i was able to compile. A lock-free hash would also be welcome.
SUMMARY:
So far i have no positive answer.
There is no "production ready" library, and amazingly none of the existent libraries complies to the API of STL contai...
I use gdb (actually DDD), and getting an element out of container is impossible. So I typically end up rolling my own loop for debugging purposes...
What do you do?
...
Is there any explanation why find() algorithm doesn't work for maps and one have to use map::find instead?
...