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 Facet> locale combine(const locale& other) const; |
| 13 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | #include <locale> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | #include <cassert> |
| 16 | |
Eric Fiselier | 4eb5b6d | 2014-12-22 22:38:59 +0000 | [diff] [blame] | 17 | #include "count_new.hpp" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | |
| 19 | void 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 | { |
| 57 | int test() const {return 5;} |
| 58 | |
| 59 | static std::locale::id id; |
| 60 | }; |
| 61 | |
| 62 | std::locale::id my_facet::id; |
| 63 | |
| 64 | int 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 Fiselier | 4eb5b6d | 2014-12-22 22:38:59 +0000 | [diff] [blame] | 77 | assert(globalMemCounter.checkOutstandingNewEq(0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | } |
Eric Fiselier | 4eb5b6d | 2014-12-22 22:38:59 +0000 | [diff] [blame] | 92 | assert(globalMemCounter.checkOutstandingNewEq(0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | } |
| 94 | } |