I have a problem that I can’t resolve. Let’s say I have this map definition:
map<string, int16_t> Registers;
but sometimes, I need to store an unsigned int16_t instead of a signed int16_t.
How can I do that?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can either use a bigger
fishtype, likeint32_t, or use aboost::variant.An
int32_tcan store all the values that anint16_tor anuint16_tcan, and it preserves the difference between, for example, 32768 and -32768 (assuming two’s complement). If you used some casting scheme withint16_tanduint16_tthe difference between these would be lost as both would be stored as 0x8000. Telling values like 0x8000 apart would require out-of-band information, which if you have, you did not mention.However,
int32_twon’t preserve the difference between 32767 signed and 32767 unsigned. If that matters, thenboost::variantcan preserve that information.