hi,
I need to use tree structure inside a ATL COM server.
I thought of using stl::map<> for this purpose as follows.
BaseMap[k1,NextLevelMap[k2, NextLevelMap[k3, Value]]]
But I need to know, whether using such a structure inside ATL is safe
and possibility of debugging support with maps.
Thank you
...
I have a hash map defined as
class KeyType {
int key;
mutable bool flag;
KeyType(int key) : key(key), flag(false) {}
void setFlag() const { flag = true; }
};
struct KeyType_hasher {
size_t operator()(const KeyType& s) const {
return static_cast<size_t> key;
}
};
struct KeyType_equal {
size_t operat...
Lets say, we have string "ABCAD", now we need to iterate through all possible arrangement of this string in both clockwise and counter-clockwise direction.
My ugly implementation looks like this:
string s = "ABCAD";
string t ="";
for(int i = 0; i < sz(s); i++){
t = s[i];
for(int j = i+1; ; j++){
if((j) == sz(s)){
...
std::list <std::list <int>> mylist;
std::list <int> mylist_;
mylist_.push_back(0);
mylist.push_back(mylist_);
is it possible to insert a sub-list into the list (mylist) without creating the temporary local sub-list (mylist_) and would it be better to use the type (sub-list) as pointer in list (mylist) in terms of per...
Let's imagine I want to make a templated function that returns the first element of any stl container. The general way would be :
template<typename Container>
Container::value_type first(Container c){
return *(c.begin());
}
This works for vectors, lists, deques, sets and so on.
However, for pair associative containers (std::map),...
I want to add logging support to a COM object (DLL) of mine, and there are usually at least two instances of this object loaded. I want both of the DLLs to be able to write lines to the same text file but am worried that this is going to give me problems. Is this possible to achieve? Am I right in thinking that a single Windows API Wr...
We need ADT having search and rank features.
That is, in addition to the interface of STL map, a function 'int get_rank(key)' is required.
Standard implementation of such function requires supporting and updating an extra integer field in every node of self-balanced searching tree (e.g., in black-red tree, used in STL map/set).
But it s...
I'm trying to use istringstream to recreate an encoded wstring from some memory. The memory is laid out as follows:
1 byte to indicate the start of the wstring encoding. Arbitrarily this is '!'.
n bytes to store the character length of the string in text format, e.g. 0x31, 0x32, 0x33 would be "123", i.e. a 123-character string
1 byte s...
I've read that accessing elements by position index can be done in constant time in a STL deque. As far as I know, elements in a deque may be stored in several non-contiguous locations, eliminating safe access through pointer arithmetic. For example:
abc->defghi->jkl->mnop
The elements of the deque above consists of a single character....
Im using a STL vector in my SDL program. and it looks like this: vector< Bullet * > vec; this makes a vector that can contain pointers to Bullet objects. when i run my program i only add one item at a time using: vec.push_back( new_bullet ); (new_bullet is a pointer to a "new" Bullet object. then in a following function i erase an object...
Hi, I was reading the STL source code (which turned out to be both fun and very useful), and I came across this kind of thing
//file backwards/auto_ptr.h, but also found on many others.
template<typename _Tp>
class auto_ptr
//Questio...
Hi,
what of those two is faster for random insertions and deletions? I guess list, having the values as the keys as it is with sets seems to be attractive too though.
Is performance similar for iterating over the whole container?
Thanks!
...
I'd like to design a class Foo that stores various data of different types and returns iterators over them. It's supposed to be generic, so the user of Foo does not know how the data is stored (Foo could be using std::set or std::vector or whatever).
I'm tempted to write an interface like this:
class Foo {
class FooImpl;
FooImpl* i...
Consider the following C++ program, which takes a file and prints each line. It's a slice of a larger program where I later append to the file, based on what I see.
#include <fstream>
using std::fstream;
#include <iostream>
#include <string>
using std::string;
int main()
{
fstream file("file.txt", fstream::in | fstream::out | fstream:...
I am writing code that inserts rows from a database into a vector. The vectors are then stored in a std::map. This architecture allows me to logically partition the datasets (vectors), based on the map key.
In my code, I will be retrieving a dataset (i.e. vector) from the std::map, adding/removing rows to it or performing some other log...
I have a legacy data structure that's 672 bytes long. These structs are stored in a file, sequentially, and I need to read them in.
While I can read them in one-by-one, it would be nice to do this:
// I know in advance how many structs to read in
vector<MyStruct> bunchOfStructs;
bunchOfStructs.resize(numberOfStructs);
ifstream ifs;
if...
I want to find an element in the map using map::find(key), and then iterate the map in reverse order from the point where I found the element, till the beginning (i.e. until map::rend()).
However, I get a compile error when I try to assign my iterator to a reverse_iterator. How do I solve this?
...
To retrieve the smallest value i have to use numeric_limits<int>::min()
I suppose the smallest int is -2147483648, and tests on my machine showed this result.
But some C++ references like Open Group Base Specifications and
cplusplus.com define it with the value -2147483647.
I ask this question because in my implementation of the negaMa...
Instead of the STL and similar libraries in other languages?
As a newbie, how much should I delve into this part of software development? Breadth first or depth?
Is only a conceptual understanding necessary these days? Or should I be able to implement a doubly linked list blindfolded?
...
If I'd like to know how a function written in like standard C++ library work (not just the MSDN description). I mean how does it allocate, manage, deallocate memory and return you the result. where or what do you need to know to understand that?
...