how to typedef array of 4 char to be used in map template
-
That (probably) gives type mismatch because you declared the map this way
map
But you shouldn't do that. Instead you should declare it like
map
"In testa che avete, Signor di Ceprano?" -- Rigoletto
now I am I am getting this
\]
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '1': no conversion from 'ESDID' to 'std::pair'
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '2': no conversion from 'syminfo' to 'std::pair'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xtree(1283,10): message : see declaration of 'std::_Tree>::insert'
1> with
1> [
1> _Kty=uint32_t,
1> _Ty=syminfo,
1> _Pr=std::less,
1> _Alloc=std::allocator>
1> ] -
now I am I am getting this
\]
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '1': no conversion from 'ESDID' to 'std::pair'
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '2': no conversion from 'syminfo' to 'std::pair'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xtree(1283,10): message : see declaration of 'std::_Tree>::insert'
1> with
1> [
1> _Kty=uint32_t,
1> _Ty=syminfo,
1> _Pr=std::less,
1> _Alloc=std::allocator>
1> ] -
Did you try
procpointer->extsymcollector.insert(std::pair(exsympointer->SYMESDID(), *exsympointer ));
?
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
But you need the values of ESDID characters as key for the map. something like this could do the trick
struct ESDID
{
char c[4];
uint32_t operator()(){return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//..
map m;
//..
syminfo s1;
m.insert( pair(s1.symesdid(), s1) );"In testa che avete, Signor di Ceprano?" -- Rigoletto
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
}; -
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
};That compiles. However it is probably NOT what you want (both the key of the map and the
<
operator use the address of thec
array). RunESDID e1, e2;
// init e1, e2 with the same content
e1.c[0] = e1.c[1] = e1.c[2] = e1.c[3] = 'A';
e2.c[0] = e2.c[1] = e2.c[2] = e2.c[3] = 'A';cout << std::boolalpha;
cout << "(e1 < e2) " << (e1 < e2) << "\n";
cout << "(e2 < e1) " << (e2 < e1) << "\n";and watch the resulting output. Can you spot the problem? You can do something like this:
struct ESDID
{
char c[4];
// overload of the cast operator
operator uint32_t () const { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//...
syminfo s1;
map m;
m.insert( pair(s1.symesdid, s1) );Note the key of the map uses the content of the
c
array."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
}; -
That compiles. However it is probably NOT what you want (both the key of the map and the
<
operator use the address of thec
array). RunESDID e1, e2;
// init e1, e2 with the same content
e1.c[0] = e1.c[1] = e1.c[2] = e1.c[3] = 'A';
e2.c[0] = e2.c[1] = e2.c[2] = e2.c[3] = 'A';cout << std::boolalpha;
cout << "(e1 < e2) " << (e1 < e2) << "\n";
cout << "(e2 < e1) " << (e2 < e1) << "\n";and watch the resulting output. Can you spot the problem? You can do something like this:
struct ESDID
{
char c[4];
// overload of the cast operator
operator uint32_t () const { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//...
syminfo s1;
map m;
m.insert( pair(s1.symesdid, s1) );Note the key of the map uses the content of the
c
array."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
Alternatively you could use a union?
const struct ESDID
{
union
{
char c[4];
uint32_t i;
} x;
bool operator< (const ESDID e) const { return x.i < e.x.i; }
}; -
thanks richard I dont see in the map documentation when using the insert method with key of type struct '<' operator must be overloaded by the user
Actually there is (see std::map - cppreference.com[^]):
template<
class Key,
class T,
class Compare = std::less,
class Allocator = std::allocator>class map;
As it should be, because the
std::map
is a sorted container."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
I understand the compare wont work correctly however what I dont see where the cast operator () is being used> Is dynamic cast used with pair i.e <> the same as the () operator ()
-
Actually there is (see std::map - cppreference.com[^]):
template<
class Key,
class T,
class Compare = std::less,
class Allocator = std::allocator>class map;
As it should be, because the
std::map
is a sorted container."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
That’s not the way the map template is defined by Microsoft map Class | Microsoft Learn[^]
template<
class Key,
class T,
class Compare = std::less,
class Allocator = std::allocator>class map;
Microsoft:
template ,
class Allocator=allocator>>
class map;Do you see significant differences?
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
template<
class Key,
class T,
class Compare = std::less,
class Allocator = std::allocator>class map;
Microsoft:
template ,
class Allocator=allocator>>
class map;Do you see significant differences?
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
I see the third parameter to the template in microsoft docs is class traits in the cpp reference its class compare thank you
-
That's, you know, just a matter of naming... BTW, you are welcome.
"In testa che avete, Signor di Ceprano?" -- Rigoletto
this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code Thank
-
this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code Thank
-
this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code Thank
-
You might use
find
, to the purpose (see std::map<Key,T,Compare,Allocator>::find - cppreference.com[^])."In testa che avete, Signor di Ceprano?" -- Rigoletto
Thank you again you know I’m an assembler mail framer by birth when I post any question on IBMMAIN no matter how much research I have done I get screamed at wish IBMMAIN could be more like the codeproject thank. Time for to implement my code or actually yours