Travis Vitek wrote:
> 
> 
> 
> Ravi Inampudi-2 wrote:
>> 
>> There is no template for "omanip" in C++ standard library.
>> 
> 
> I'm pretty sure that omanip was something from the old iostreams
> implementation. It is not in the standard.
> 
> 
> Ravi Inampudi-2 wrote:
>> 
>> What are the options for people migrating to C++ standard library?
>> 
> 
> The option is to write out the code explicitly. The model would be
> something like this...
> 
>     #include <iostream>
> 
>     template <class CharT>
>     struct repeat_n_impl {
>       repeat_n_impl (CharT c, size_t n)
>         : c_ (c), n_ (n)
>       {
>       }
> 
>       CharT c_;
>       size_t n_;
>     };
> 
>     template <class CharT, class TraitsT>
>     std::basic_ostream<CharT, TraitsT>& operator<< (
>         std::basic_ostream<CharT, TraitsT>& os,
>         const repeat_n_impl<CharT>& rep)
>     {
>       for (size_t n = 0; n < rep.n_; ++n)
>           os << rep.c_;
>       return os;
>     }
> 
>     template <class CharT>
>     repeat_n_impl<CharT> repeat_n (CharT c, size_t n) {
>       return repeat_n_impl<CharT>(c, n);
>     }
> 
>     int main ()
>     {
>         std::cout << repeat_n ('a', 100) << std::endl;
>         return 0;
>     }
> 
> Another option would be to implement something like the old omanip
> template. Unfortunately I only think that omanip worked for one additional
> parameter, so it wouldn't work with the above example. I believe that the
> following is similar...
> 
>     template <class T>
>     struct omanip
>     {
>         typedef std::ostream& (*omanip_function)(std::ostream&, T);
> 
>         omanip (omanip_function fn, T val)
>             : fn_ (fn), val_ (val)
>         {
>         }
> 
>         friend std::ostream& operator<< (std::ostream& os, const omanip&
> om)
>         {
>             return om.fn_ (os, om.val_);
>         }
> 
>         omanip_function fn_;
>         T val_;
>     };
> 
> Travis
> 

Another disadvantage of this is that it doesn't work with other stream
types. I.e. it doesn't work with std::wostream. You could make some
modifications, but the syntax that the user would need to write would
change.

Travis

-- 
View this message in context: 
http://www.nabble.com/%22omanip%22-in-C%2B%2B-standard-library-tp15194916p15195204.html
Sent from the stdcxx-dev mailing list archive at Nabble.com.

Reply via email to