On 10/15/2017 03:28 PM, Laurent BP wrote:
I would like to make const a rtl::Static. I tryed:
struct MyConstStatic : public rtl::Static<const MyType, MyConstStatic> {};
First of all, internal LO code no longer needs to use rtl::Static, as 
all relevant toolchains support C++11 "magic statics" by now.
But now, how to initialize it? How when it is an array like NfKeywordTable
https://opengrok.libreoffice.org/xref/core/include/svl/nfkeytab.hxx#107
If you need something other than a default-initialized T, there's 
rtl::StaticWithInit.  With your specific example, that would be 
something like
struct MyConstStaticInit {
    NfKeywordTable operator ()() {
        NfKeywordTable t;
        t[NF_KEY_E] = "...";
        t[NF_KEY_AMPM] = "...";
        // ...
        t[NF_KEY_THAI_T] = "...";
        return t;
    }
};
struct MyConstStatic:
    public rtl::StaticWithInit<NfKeywordTable const, MyConstStaticInit>
{};
OUString test(NfKeywordIndex n) { return MyConstStatic::get()[n]; }
(But of course a class that, unlike the existing NfKeywordTable, can be 
initialized with a std::initializer_list would be more useful in such a 
case.  Together with the non-necessity to use rtl::Static in the first 
place, all could boil down to something like
OUString test(NfKeywordIndex n) {
    static NfKeywordTable const t{"...", "...", /*...*/ "..."};
    return t[n];
};
then.)
Context
   
 
  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.