1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <locale>
10
11// template <class charT> class collate;
12
13// explicit collate(size_t refs = 0);
14
15#include <locale>
16#include <type_traits>
17#include <cassert>
18
19#include "test_macros.h"
20
21template <class C>
22class my_facet
23 : public std::collate<C>
24{
25public:
26 static int count;
27
28 explicit my_facet(std::size_t refs = 0)
29 : std::collate<C>(refs) {++count;}
30
31 ~my_facet() {--count;}
32};
33
34template <class C> int my_facet<C>::count = 0;
35
36int main(int, char**)
37{
38 {
39 std::locale l(std::locale::classic(), new my_facet<char>);
40 assert(my_facet<char>::count == 1);
41 }
42 assert(my_facet<char>::count == 0);
43 {
44 my_facet<char> f(1);
45 assert(my_facet<char>::count == 1);
46 {
47 std::locale l(std::locale::classic(), &f);
48 assert(my_facet<char>::count == 1);
49 }
50 assert(my_facet<char>::count == 1);
51 }
52 assert(my_facet<char>::count == 0);
53
54#ifndef TEST_HAS_NO_WIDE_CHARACTERS
55 {
56 std::locale l(std::locale::classic(), new my_facet<wchar_t>);
57 assert(my_facet<wchar_t>::count == 1);
58 }
59 assert(my_facet<wchar_t>::count == 0);
60 {
61 my_facet<wchar_t> f(1);
62 assert(my_facet<wchar_t>::count == 1);
63 {
64 std::locale l(std::locale::classic(), &f);
65 assert(my_facet<wchar_t>::count == 1);
66 }
67 assert(my_facet<wchar_t>::count == 1);
68 }
69 assert(my_facet<wchar_t>::count == 0);
70#endif
71
72 return 0;
73}
74

source code of libcxx/test/std/localization/locale.categories/category.collate/locale.collate/ctor.pass.cpp