C++ question: literal form of std::map<int, std::array>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx)
_______________________________________________
LibreOffice mailing list
LibreOffice@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/libreoffice



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux