Click to See Complete Forum and Search --> : Please help: STL multimap causes compiler error


Alan Benett
May 13th, 1999, 07:39 AM
Hello!

I'm using the STLport with VC 4.0.
Well, it works somehow in most cases...
However, the following lines of code produce an internal compiler error.
(I put a little more of the code in this post, because i don't know where exactly to look
for the error...!)

If anybody out there has the patience to help me with this problem, i'd be very pleased.
Here's the code:

// Typedefs for Word-List-Map
typedef map <CString, int, ltstr> word_map;
typedef pair<CString, int> wmap_data;
typedef word_map::iterator wmap_iter;

// Typedefs for Value-Map
typedef multimap <int, wmap_iter, less<int> > val_map;
typedef pair<int, wmap_iter> vmap_data;
typedef val_map::iterator vmap_iter;
typedef pair<vmap_iter, vmap_iter> vmap_range;
typedef val_map::size_type vmap_size;

// just for testing... array of character-values
// (value of 'a' or 'A' at array[0], of 'b' or 'B' at array[1], etc.)
int char_vals[27] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};

void CTestDoc::OnTestCreatecollection()
{
// declare the maps
word_map wmap;
val_map vmap;

// Add some strings to the word-list
CString cstr("einsaaaa");
wmap.insert (wmap_data(cstr, 0));
cstr = "zweiaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "dreiaaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "vieraaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "fuenfaaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "sechsaaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "siebenaaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "achtaaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "neunaaaaa";
wmap.insert (wmap_data(cstr, 0));
cstr = "zehnaaaaa";
wmap.insert (wmap_data(cstr, 0));

// Trace the word-list
wmap_iter wit;
for (wit = wmap.begin(); wit != wmap.end(); wit++)
TRACE ("Key = %s, Value = %d\n", (*wit).first, (*wit).second);

// Now simulate a calculation of the word-values
// Iterate through the word-map and calculate each word's value
LPCTSTR buf;
int p, l, v;
AfxMessageBox ("Starting now!"); // to "measure" time
for (int repeat = 0; repeat < 10000; repeat++)
{
for (wit = wmap.begin(); wit != wmap.end(); wit++)
{
buf = LPCTSTR ((*wit).first);
v = 0;
for (l = ((*wit).first).GetLength(); l > 0; l--)
{
v += char_vals[(*(buf++) - 97)];
}
// Now enter the value in the word-map
// and make the corresponding entry in the value-map
(*wit).second = v;
vmap.insert (vmap_data(v, wit));
}
}
AfxMessageBox ("Ready!"); // to "measure" time

// check how many words have a certain value
wit = wmap.begin();
const int vl = (*wit).second;

// Get a range of words with equal values
// **************************************************
vmap_range vr = vmap.equal_range (vl);
// **************************************************
// The above line causes an internal compiler error:
// >> D:\ProgDev\STLport-3.12.3\stl\stl_pair.h(48) : fatal error C1001:
// INTERNAL COMPILER ERROR
// (compiler file '\school.tp3\test\c10\src\P2\main.c', line 413) <<
}

I have no idea, what causes this error. I already used the equal_range-function
successfully...

Appreciating any help.
Regards.
Alan.