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 numpunct;
12
13// explicit numpunct(size_t refs = 0);
14
15#include <locale>
16#include <cassert>
17
18#include "test_macros.h"
19
20template <class C>
21class my_facet
22 : public std::numpunct<C>
23{
24public:
25 static int count;
26
27 explicit my_facet(std::size_t refs = 0)
28 : std::numpunct<C>(refs) {++count;}
29
30 ~my_facet() {--count;}
31};
32
33template <class C> int my_facet<C>::count = 0;
34
35int main(int, char**)
36{
37 {
38 std::locale l(std::locale::classic(), new my_facet<char>);
39 assert(my_facet<char>::count == 1);
40 }
41 assert(my_facet<char>::count == 0);
42 {
43 my_facet<char> f(1);
44 assert(my_facet<char>::count == 1);
45 {
46 std::locale l(std::locale::classic(), &f);
47 assert(my_facet<char>::count == 1);
48 }
49 assert(my_facet<char>::count == 1);
50 }
51 assert(my_facet<char>::count == 0);
52
53#ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 {
55 std::locale l(std::locale::classic(), new my_facet<wchar_t>);
56 assert(my_facet<wchar_t>::count == 1);
57 }
58 assert(my_facet<wchar_t>::count == 0);
59 {
60 my_facet<wchar_t> f(1);
61 assert(my_facet<wchar_t>::count == 1);
62 {
63 std::locale l(std::locale::classic(), &f);
64 assert(my_facet<wchar_t>::count == 1);
65 }
66 assert(my_facet<wchar_t>::count == 1);
67 }
68 assert(my_facet<wchar_t>::count == 0);
69#endif // TEST_HAS_NO_WIDE_CHARACTERS
70
71 return 0;
72}
73

source code of libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct/ctor.pass.cpp