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 // REQUIRES: locale.en_US.UTF-8 11 12 // <ios> 13 14 // class ios_base 15 16 // void register_callback(event_callback fn, int index); 17 18 #include <ios> 19 #include <string> 20 #include <locale> 21 #include <cassert> 22 23 #include "platform_support.h" // locale name macros 24 25 class test 26 : public std::ios 27 { 28 public: test()29 test() 30 { 31 init(0); 32 } 33 }; 34 35 int f1_called = 0; 36 f1(std::ios_base::event ev,std::ios_base & stream,int index)37void f1(std::ios_base::event ev, std::ios_base& stream, int index) 38 { 39 if (ev == std::ios_base::imbue_event) 40 { 41 assert(stream.getloc().name() == LOCALE_en_US_UTF_8); 42 assert(index == 4); 43 ++f1_called; 44 } 45 } 46 main()47int main() 48 { 49 test t; 50 std::ios_base& b = t; 51 b.register_callback(f1, 4); 52 b.register_callback(f1, 4); 53 b.register_callback(f1, 4); 54 std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8)); 55 assert(f1_called == 3); 56 } 57