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