How to use string constants with std::map
Regina Henschel
rb.henschel at t-online.de
Wed Oct 11 18:44:17 UTC 2023
Hi Stephan,
thank you for the quick answer. Generating the longer u"cd4"_ustr for
example is no problem in XSLT. So I will likely go with that.
The hint about "not constexpr-ready" is helpful too. I have indeed
thought about whether to use it.
Kind regards,
Regina
Stephan Bergmann schrieb am 11.10.2023 um 20:14:
> On 10/11/23 19:24, Regina Henschel wrote:
>> How to write the map? In the past it would have been something like
>> the following:
>>
>> static const std::map<OUString, std::vector<OUString>>
>> aConnectionSiteAngleMap{
>> {"accentBorderCallout1",{"0","cd4","cd2","3cd4"}},
>> ...
>> {"wedgeRoundRectCallout",{"3cd4","cd2","cd4","0","cd4"}}
>> };
>>
>> All strings are constants and neither the map nor the strings will
>> ever change.
>>
>> How do I have to write it now?
>
> You can keep writing it as above, or your could write it as
>
>> static const std::map<OUString, std::vector<OUString>>
>> aConnectionSiteAngleMap{
>>
>> {u"accentBorderCallout1"_ustr,{u"0"_ustr,u"cd4"_ustr,u"cd2"_ustr,u"3cd4"_ustr}},
>>
>> ...
>>
>> {u"wedgeRoundRectCallout"_ustr,{u"3cd4"_ustr,u"cd2"_ustr,u"cd4"_ustr,u"0"_ustr,u"cd4"_ustr}}
>>
>> };
>
> which is a bit more efficient as it doesn't need to construct the
> OUString instances it runtime (but it still needs to construct the
> std::vector and std::map instances at runtime).
>
> (You can't write it as
>
>> static constexpr std::map<OUString, std::vector<OUString>>
>> aConnectionSiteAngleMap{
>>
>> {u"accentBorderCallout1"_ustr,{u"0"_ustr,u"cd4"_ustr,u"cd2"_ustr,u"3cd4"_ustr}},
>>
>> ...
>>
>> {u"wedgeRoundRectCallout"_ustr,{u"3cd4"_ustr,u"cd2"_ustr,u"cd4"_ustr,u"0"_ustr,u"cd4"_ustr}}
>>
>> };
>
> as std::map is not constexpr-ready in C++20, and neither is std::vector
> in some standard library implementations, like in debug-mode libstdc++.)
>
>
More information about the LibreOffice
mailing list