Example #1
0
        void to_stream(T const& value)
        {
            std::locale loc = m_Stream.getloc();
            if (!std::has_facet< FacetT >(loc))
            {
                // Add the formatting facet
                std::auto_ptr< FacetT > facet(new FacetT(m_Format.c_str()));
                m_Stream.imbue(std::locale(loc, facet.get()));
                facet.release();
                loc = m_Stream.getloc();
            }

            // Perform formatting
            std::ostreambuf_iterator< char_type > osb_it(m_Stream);
            std::use_facet< FacetT >(loc).put(osb_it, m_Stream, m_Stream.fill(), value);
        }
 //! Put date into an ostream
 static void date_put(const date_type& d,
                      ostream_type& os)
 {
   //retrieve the local from the ostream
   std::locale locale = os.getloc();
   if (std::has_facet<facet_type>(locale)) {
     const facet_type& f = std::use_facet<facet_type>(locale);
     date_put(d, os, f);
   }
   else {
     //default to something sensible if no facet installed
     facet_type default_facet;
     date_put(d, os, default_facet);
   }
 } // date_to_ostream