Home | History | Annotate | Download | only in locale.time.put.members
      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 // class time_put<charT, OutputIterator>
     13 
     14 // iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
     15 //               const charT* pattern, const charT* pat_end) const;
     16 
     17 #include <locale>
     18 #include <cassert>
     19 #include "test_iterators.h"
     20 
     21 typedef std::time_put<char, output_iterator<char*> > F;
     22 
     23 class my_facet
     24     : public F
     25 {
     26 public:
     27     explicit my_facet(std::size_t refs = 0)
     28         : F(refs) {}
     29 };
     30 
     31 int main()
     32 {
     33     const my_facet f(1);
     34     char str[200];
     35     output_iterator<char*> iter;
     36     tm t;
     37     t.tm_sec = 6;
     38     t.tm_min = 3;
     39     t.tm_hour = 13;
     40     t.tm_mday = 2;
     41     t.tm_mon = 4;
     42     t.tm_year = 109;
     43     t.tm_wday = 6;
     44     t.tm_yday = -1;
     45     t.tm_isdst = 1;
     46     std::ios ios(0);
     47     {
     48         std::string pat("Today is %A which is abbreviated %a.");
     49         iter = f.put(output_iterator<char*>(str), ios, '*', &t,
     50                      pat.data(), pat.data() + pat.size());
     51         std::string ex(str, iter.base());
     52         assert(ex == "Today is Saturday which is abbreviated Sat.");
     53     }
     54     {
     55         std::string pat("The number of the month is %Om.");
     56         iter = f.put(output_iterator<char*>(str), ios, '*', &t,
     57                      pat.data(), pat.data() + pat.size());
     58         std::string ex(str, iter.base());
     59         assert(ex == "The number of the month is 05.");
     60     }
     61 }
     62