1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3// Copyright (c) 2024 Alexander Grund
4//
5// Distributed under the Boost Software License, Version 1.0.
6// https://www.boost.org/LICENSE_1_0.txt
7
8#include <boost/locale/boundary.hpp>
9#include <boost/locale/collator.hpp>
10#include <boost/locale/conversion.hpp>
11#include <boost/locale/date_time_facet.hpp>
12#include <boost/locale/info.hpp>
13#include <boost/locale/message.hpp>
14#include "boost/locale/util/foreach_char.hpp"
15#include <boost/core/ignore_unused.hpp>
16
17namespace boost { namespace locale {
18 namespace detail {
19 template<class Derived>
20 std::locale::id facet_id<Derived>::id;
21 } // namespace detail
22#define BOOST_LOCALE_DEFINE_ID(CLASS) template struct detail::facet_id<CLASS>
23
24 BOOST_LOCALE_DEFINE_ID(info);
25 BOOST_LOCALE_DEFINE_ID(calendar_facet);
26
27#define BOOST_LOCALE_INSTANTIATE(CHARTYPE) \
28 BOOST_LOCALE_DEFINE_ID(collator<CHARTYPE>); \
29 BOOST_LOCALE_DEFINE_ID(converter<CHARTYPE>); \
30 BOOST_LOCALE_DEFINE_ID(message_format<CHARTYPE>); \
31 BOOST_LOCALE_DEFINE_ID(boundary::boundary_indexing<CHARTYPE>);
32
33 BOOST_LOCALE_FOREACH_CHAR(BOOST_LOCALE_INSTANTIATE)
34#undef BOOST_LOCALE_INSTANTIATE
35
36 namespace {
37 // Initialize each facet once to avoid issues where doing so
38 // in a multi threaded environment could cause problems (races)
39 struct init_all {
40 init_all()
41 {
42 const std::locale& l = std::locale::classic();
43#define BOOST_LOCALE_INIT_BY(CHAR) init_by<CHAR>(l);
44 BOOST_LOCALE_FOREACH_CHAR(BOOST_LOCALE_INIT_BY)
45
46 init_facet<info>(l);
47 init_facet<calendar_facet>(l);
48 }
49 template<typename Char>
50 void init_by(const std::locale& l)
51 {
52 init_facet<boundary::boundary_indexing<Char>>(l);
53 init_facet<collator<Char>>(l);
54 init_facet<converter<Char>>(l);
55 init_facet<message_format<Char>>(l);
56 }
57 template<typename Facet>
58 void init_facet(const std::locale& l)
59 {
60 // Use the facet to initialize e.g. their std::locale::id
61 ignore_unused(std::has_facet<Facet>(l));
62 }
63 } facet_initializer;
64 } // namespace
65
66}} // namespace boost::locale
67

source code of boost/libs/locale/src/boost/locale/shared/ids.cpp