aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/locale/src/shared/ids.cpp
blob: 2d5ef255a39a780c08595c29ab79a012ba72b373 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
// Copyright (c) 2024 Alexander Grund
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/locale/boundary.hpp>
#include <boost/locale/collator.hpp>
#include <boost/locale/conversion.hpp>
#include <boost/locale/date_time_facet.hpp>
#include <boost/locale/info.hpp>
#include <boost/locale/message.hpp>
#include "../util/foreach_char.hpp"
#include <boost/core/ignore_unused.hpp>

namespace boost { namespace locale {
    namespace detail {
        template<class Derived>
        std::locale::id facet_id<Derived>::id;
    } // namespace detail
#define BOOST_LOCALE_DEFINE_ID(CLASS) template struct detail::facet_id<CLASS>

    BOOST_LOCALE_DEFINE_ID(info);
    BOOST_LOCALE_DEFINE_ID(calendar_facet);

#define BOOST_LOCALE_INSTANTIATE(CHARTYPE)            \
    BOOST_LOCALE_DEFINE_ID(collator<CHARTYPE>);       \
    BOOST_LOCALE_DEFINE_ID(converter<CHARTYPE>);      \
    BOOST_LOCALE_DEFINE_ID(message_format<CHARTYPE>); \
    BOOST_LOCALE_DEFINE_ID(boundary::boundary_indexing<CHARTYPE>);

    BOOST_LOCALE_FOREACH_CHAR(BOOST_LOCALE_INSTANTIATE)
#undef BOOST_LOCALE_INSTANTIATE

    namespace {
        // Initialize each facet once to avoid issues where doing so
        // in a multi threaded environment could cause problems (races)
        struct init_all {
            init_all()
            {
                const std::locale& l = std::locale::classic();
#define BOOST_LOCALE_INIT_BY(CHAR) init_by<CHAR>(l);
                BOOST_LOCALE_FOREACH_CHAR(BOOST_LOCALE_INIT_BY)

                init_facet<info>(l);
                init_facet<calendar_facet>(l);
            }
            template<typename Char>
            void init_by(const std::locale& l)
            {
                init_facet<boundary::boundary_indexing<Char>>(l);
                init_facet<collator<Char>>(l);
                init_facet<converter<Char>>(l);
                init_facet<message_format<Char>>(l);
            }
            template<typename Facet>
            void init_facet(const std::locale& l)
            {
                // Use the facet to initialize e.g. their std::locale::id
                ignore_unused(std::has_facet<Facet>(l));
            }
        } facet_initializer;
    } // namespace

}} // namespace boost::locale