1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <locale> 11 12 // template <class Facet> locale combine(const locale& other) const; 13 14 #include <locale> 15 #include <cassert> 16 17 #include "count_new.hpp" 18 check(const std::locale & loc)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 54 struct my_facet 55 : public std::locale::facet 56 { testmy_facet57 int test() const {return 5;} 58 59 static std::locale::id id; 60 }; 61 62 std::locale::id my_facet::id; 63 main()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 } 77 assert(globalMemCounter.checkOutstandingNewEq(0)); 78 } 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 } 92 assert(globalMemCounter.checkOutstandingNewEq(0)); 93 } 94 } 95