Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <locale> |
| 11 | |
| 12 | // template <> class codecvt_byname<wchar_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 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 20 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> F; |
| 23 | |
| 24 | class my_facet |
| 25 | : public F |
| 26 | { |
| 27 | public: |
| 28 | static int count; |
| 29 | |
| 30 | explicit my_facet(const char* nm, std::size_t refs = 0) |
| 31 | : F(nm, refs) {++count;} |
| 32 | explicit my_facet(const std::string& nm, std::size_t refs = 0) |
| 33 | : F(nm, refs) {++count;} |
| 34 | |
| 35 | ~my_facet() {--count;} |
| 36 | }; |
| 37 | |
| 38 | int my_facet::count = 0; |
| 39 | |
| 40 | int main() |
| 41 | { |
| 42 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 43 | std::locale l(std::locale::classic(), new my_facet(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | assert(my_facet::count == 1); |
| 45 | } |
| 46 | assert(my_facet::count == 0); |
| 47 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 48 | my_facet f(LOCALE_en_US_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | assert(my_facet::count == 1); |
| 50 | { |
| 51 | std::locale l(std::locale::classic(), &f); |
| 52 | assert(my_facet::count == 1); |
| 53 | } |
| 54 | assert(my_facet::count == 1); |
| 55 | } |
| 56 | assert(my_facet::count == 0); |
| 57 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 58 | std::locale l(std::locale::classic(), new my_facet(std::string(LOCALE_en_US_UTF_8))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | assert(my_facet::count == 1); |
| 60 | } |
| 61 | assert(my_facet::count == 0); |
| 62 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 63 | my_facet f(std::string(LOCALE_en_US_UTF_8), 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | assert(my_facet::count == 1); |
| 65 | { |
| 66 | std::locale l(std::locale::classic(), &f); |
| 67 | assert(my_facet::count == 1); |
| 68 | } |
| 69 | assert(my_facet::count == 1); |
| 70 | } |
| 71 | assert(my_facet::count == 0); |
| 72 | } |