Hello,
I'm a not good C++ programmer so I want to ask you.
Now I'm trying to resolve tdf#130140 and tdf#130193, both of them
relate to the mapping between NatNum of Calc and DBNum of Excel.
Before that, I want to refactor current switch-and-if nesting
implementation of MapDBNumToNatNum() and MapNatNumToDBNum() to easy to
understand how to map these. I thought it would be nice if we can
write as:
--------------------------
static const std::map<LanguageType, std::vector<sal_uInt8>> tblDBNumToNatNum
= { { primary(LANGUAGE_CHINESE), { 4, 5, 6, 0 } },
{ primary(LANGUAGE_JAPANESE), { 4, 5, 3, 0 } },
{ primary(LANGUAGE_KOREAN), { 1, 2, 3, 9 } } };
sal_uInt8 SvNumberNatNum::MapDBNumToNatNum( sal_uInt8 nDBNum,
LanguageType eLang, bool bDate )
{
...
if (tblDBNumToNatNum.count(eLang) != 0)
{
nNatNum = tblDBNumToNatNum.at(eLang)[nDBNum - 1];
}
else
{
nNatNum = 0;
}
}
return nNatNum;
}
--------------------------
The code above works fine in my local build, but the " {4, 5, 6, 0}"
or else has a constant length, so I thought it is better to use
std::array instead of std::vector, but I couldn't write:
--------------------------
static const std::map<LanguageType, std::array<sal_uInt8, 4>> tblDBNumToNatNum
= { { primary(LANGUAGE_CHINESE), { 4, 5, 6, 0 } },
{ primary(LANGUAGE_JAPANESE), { 4, 5, 3, 0 } },
{ primary(LANGUAGE_KOREAN), { 1, 2, 3, 9 } } };
--------------------------
The compiler claimed:
--------------------------
Error (active) E0289 no instance of constructor "std::map<_Kty, _Ty,
_Pr, _Alloc>::map [with _Kty=LanguageType, _Ty=std::array<sal_uInt8,
4U>, _Pr=std::less<LanguageType>,
_Alloc=std::allocator<std::pair<const LanguageType,
std::array<sal_uInt8, 4U>>>]" matches the argument list
--------------------------
I may do a very easy mistake, so could you give me a hint?
Best,
--
Naruhiko NARU Ogasawara (naruoga@gmail.com)
Context
- C++ question: literal form of std::map<int, std::array> · Naruhiko Ogasawara
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.