Hello everyone,
quite a funny question I have.
I am working now on the HTML parser and I was using vector for all my input purposes which seemed quite fine and fast for creating tree.
In another application I need to edit HTML structure and now inserting or reordering of the elements would be extremely painful using vector so I decid...
Hello,
I have few questions regarding this topic. How does multiset works? I mean if set cant have value mapped to a key and it only holds keys? Also how all of these associative containers works? I mean vector and deque in the memory is hold sequentially it means that deleting/removing(except beggining(deque) and end(vector,deque) is sl...
From cplusplus.com:
template < class Key, class Compare = less<Key>,
class Allocator = allocator<Key> > class set;
"Compare: Comparison class: A class that takes two arguments of the same type as the container elements and returns a bool. The expression comp(a,b), where comp is an object of this comparison class and a and b are...
I'm using a std::deque to store a fairly large number of objects. If I remove a bunch of those objects, it appears to me that its memory usage does not decrease, in a similar fashion to std::vector.
Is there a way to reduce it? I know that in a vector you have to use the 'swap trick', which I assume would work here too, but I'd rather a...
I am trying to Union two sets with map. I have two sets and would like to combine them into a third one. I get an error for this code in the push_back. Is there a way to do this?
map<char, vector<char> > numbers;
map<char, vector<char> >::iterator it;
numbers['E'].push_back('a');//set1
numbers['E'].push_back('b');
numbers['E'].push_ba...
Hi all,
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit.
I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like:
for( int i = 0; i < i...
I am interested in learning Qt. I am fairly good with C++, STL and Boost. I like STL/Boost style very much, and I use them with C++ whenever I can in uni projects. However, I always miss the GUI. It seems that Qt is the best solution in my case. Qt does have a good collection of containers, but I am greatly familiar with STL/Boost stuff....
Hi,
Let's say I have an stl vector containing class type "xx". xx is abstract. I have run into the issue where the compiler won't let me "instantiate" when i do something like the following:
std::vector<xx> victor;
void pusher(xx& thing)
{
victor.push_back(thing);
}
void main()
{
;
}
I assume this is because the copy constru...
I need to iterate over a queue.
www.cplusplus.com says:
By default, if no container class is specified for a particular queue class, the standard container class template deque is used.
So can I somehow get to the queue's underlying deque and iterate over it?
Thanks.
...
From what I understand, the key in a value pair in an std::map cannot be changed once inserted. Does this mean that creating a map with the key template argument as const has no effect?
std::map<int, int> map1;
std::map<const int, int> map2;
...
typedef std::map<int, MyObject*> MyMap;
MyMap* myMap = new MyMap;
// ...
myMap->insert( MyMap::value_type( 0, objectOfType_MyObject ) );
Why does my code crash with a stack trace going down to
std::less<int>::operator()
?
I understand that if I use a custom key class that I must provide a comparator, but this is an int.
I'v...
Which STL container would fit my needs best? I basically have a 10 elements wide container in which I continually push_back new elements while pop_front ing the oldest element (about a million time).
I am currently using a std::deque for the task but was wondering if a std::list would be more efficient since I wouldn't need to realloca...
I have a simple struct :
struct MyType
{
std::string name;
std::string description;
}
and I'm putting it in a shared memory :
managed_shared_memory sharedMemory(open_or_create, "name", 65535);
MyType* pType = sharedMemory.construct<MyType>("myType")();
// ... setting pType members ...
If the two applications communicating w...
I've several writers(threads) and one reader on a stl vector.
Normal writes and reads are mutex protected, but I would like to avoid contention on a loop I have and I was wondering if vector::size would be safe enough, I suppose it depends on implementations, but since normally vector dynamic memory is for the stored items the memory wh...
When I read a text file to a wide character string (std::wstring) using an wifstream, does the stream implementation support different encodings - i.e. can it be used to read e.g. ASCII, UTF-8, and UTF-16 files?
If not, what would I have to do?
(I need to read the entire file, if that makes a difference)
...
I want to learn STL by quick browsing of real project source.
Where can I find a high quality project that uses STL?
...
That is, the computational complexity. Does it have to count all the elements? Does it depend on implementation? The SGI spec doesn't guarantee anything.
...
Hello everyone.
For some reason, I cannot get ptr_list to insert elements.
boost::ptr_list<int> somelist;
int *someint = new int(123);
int *someint2 = new int(456);
somelist.push_back(someint);
boost:: ptr_list<int>::iterator i = somelist.begin();
somelist.insert(i,someint2);
Any help, please?
...
Hi, I want to write a C++ template like this:
template <class Type1, class Type2, class Type3,....>
class MyClass
{
//...
};
But, "the number of types" is variable.
For example, a user can create an object with 3 types:
MyClass<int, int, int> obj;
or he can create an object with 5 types:
MyClass<int, int, int, in...
Why doesn't the STL string class have an overloaded char* operator built-in? Is there any specific reason for them to avoid it?
If there was one, then using the string class with C functions would become much more convenient.
I would like to know your views.
...