blob: e956102c08fcf1deda0d906e11ba4b07b027471c [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <locale>
11
12// template <class Facet> locale combine(const locale& other) const;
13
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014#include <locale>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000015#include <cassert>
16
Eric Fiselier4eb5b6d2014-12-22 22:38:59 +000017#include "count_new.hpp"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000018
19void check(const std::locale& loc)
20{
21 assert(std::has_facet<std::collate<char> >(loc));
22 assert(std::has_facet<std::collate<wchar_t> >(loc));
23
24 assert(std::has_facet<std::ctype<char> >(loc));
25 assert(std::has_facet<std::ctype<wchar_t> >(loc));
26 assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc)));
27 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
28 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
29 assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)));
30
31 assert((std::has_facet<std::moneypunct<char> >(loc)));
32 assert((std::has_facet<std::moneypunct<wchar_t> >(loc)));
33 assert((std::has_facet<std::money_get<char> >(loc)));
34 assert((std::has_facet<std::money_get<wchar_t> >(loc)));
35 assert((std::has_facet<std::money_put<char> >(loc)));
36 assert((std::has_facet<std::money_put<wchar_t> >(loc)));
37
38 assert((std::has_facet<std::numpunct<char> >(loc)));
39 assert((std::has_facet<std::numpunct<wchar_t> >(loc)));
40 assert((std::has_facet<std::num_get<char> >(loc)));
41 assert((std::has_facet<std::num_get<wchar_t> >(loc)));
42 assert((std::has_facet<std::num_put<char> >(loc)));
43 assert((std::has_facet<std::num_put<wchar_t> >(loc)));
44
45 assert((std::has_facet<std::time_get<char> >(loc)));
46 assert((std::has_facet<std::time_get<wchar_t> >(loc)));
47 assert((std::has_facet<std::time_put<char> >(loc)));
48 assert((std::has_facet<std::time_put<wchar_t> >(loc)));
49
50 assert((std::has_facet<std::messages<char> >(loc)));
51 assert((std::has_facet<std::messages<wchar_t> >(loc)));
52}
53
54struct my_facet
55 : public std::locale::facet
56{
57 int test() const {return 5;}
58
59 static std::locale::id id;
60};
61
62std::locale::id my_facet::id;
63
64int main()
65{
66{
67 {
68 std::locale loc;
69 std::locale loc2(loc, new my_facet);
70 std::locale loc3 = loc.combine<my_facet>(loc2);
71 check(loc3);
72 assert(loc3.name() == "*");
73 assert((std::has_facet<my_facet>(loc3)));
74 const my_facet& f = std::use_facet<my_facet>(loc3);
75 assert(f.test() == 5);
76 }
Eric Fiselier4eb5b6d2014-12-22 22:38:59 +000077 assert(globalMemCounter.checkOutstandingNewEq(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078}
79{
80 {
81 std::locale loc;
82 std::locale loc2;
83 try
84 {
85 std::locale loc3 = loc.combine<my_facet>(loc2);
86 assert(false);
87 }
88 catch (std::runtime_error&)
89 {
90 }
91 }
Eric Fiselier4eb5b6d2014-12-22 22:38:59 +000092 assert(globalMemCounter.checkOutstandingNewEq(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093}
94}