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 | // <ios> |
| 11 | |
| 12 | // class ios_base |
| 13 | |
| 14 | // void register_callback(event_callback fn, int index); |
| 15 | |
| 16 | #include <ios> |
| 17 | #include <string> |
| 18 | #include <locale> |
| 19 | #include <cassert> |
| 20 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 21 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 22 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | class test |
| 24 | : public std::ios |
| 25 | { |
| 26 | public: |
| 27 | test() |
| 28 | { |
| 29 | init(0); |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | int f1_called = 0; |
| 34 | |
| 35 | void f1(std::ios_base::event ev, std::ios_base& stream, int index) |
| 36 | { |
| 37 | if (ev == std::ios_base::imbue_event) |
| 38 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 39 | assert(stream.getloc().name() == LOCALE_en_US_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | assert(index == 4); |
| 41 | ++f1_called; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | int main() |
| 46 | { |
| 47 | test t; |
| 48 | std::ios_base& b = t; |
| 49 | b.register_callback(f1, 4); |
| 50 | b.register_callback(f1, 4); |
| 51 | b.register_callback(f1, 4); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 52 | std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | assert(f1_called == 3); |
| 54 | } |