Angelika Langer - Training & Consulting
HOME | COURSES | TALKS | ARTICLES | GENERICS | LAMBDAS | IOSTREAMS | ABOUT | CONTACT | Twitter | Lanyrd | Linkedin
 
HOME 
GENERICS 
LAMBDAS 

IOSTREAMS

    BOOK PAGE
    ERRATA
    ABSTRACT
    CONTENT
    PREFACE
    EXCERPT
    QUOTES
    AUTHORS
    REVIEWS
    CODE
    FORUM
    SEMINAR   
 

ABOUT 
CONTACT 
Readers Forum

 
           

Standard C++ IOStreams and Locales

Advanced Programmer's Guide and Reference

Angelika Langer & Klaus Kreft
Addison-Wesley, January 2000
ISBN 0-201-18395-1

Readers Forum
 

Discussions and Related Information

Several readers came up with ideas and suggestions of their own inspired by topics from the IOStreams book. We would like to share their ideas with interested readers by publishing them here, basically "as is" with a brief introductory comment.

List of Topics
 
  • Non-Standard Internationalization Support in C++  
  • Modern Manipulators    

  • Non-Standard Internationalization Support in C++:

    Numerous readers mentioned that they prefer the internationalization support in Java over the the internationalization support defined by the C++ Standard, which is described in our book. They felt that Java has much more to offer than C++, especially in the area of Unicode support.

    This cross-language approach, calling Java from C++, is no longer necessary. There is an open-source project called International Components for Unicode (ICU) that offers Java-style internationalization support in C++. For more information visit IBM's website at http://oss.software.ibm.com/icu/ .

    brought to our attention by:
    Werner Mossner, Siemens AG, Augsburg, January 2002

    Modern Manipulators:

    Kevlin Henney suggests a more modern technique for implementation of manipulators with parameters: he uses member function templates, function object types, and parameterized inheritance. This way he avoids passing function pointers, gets rid of the static member function, and eliminates the ugly stream type problem that we describe in section 3.2.2.2.  By and large, a very elegant solution that relies heavily on modern template programming techniques.  Kevlin's comments are in response to our article published in C++ Report in June 2000. Inspired by his ideas we later published another article on manipulators in the C/C++ Users Journal in June 2001. Below are Kevlin's thoughts on manipulators.

    suggested by:
    Kevlin Henney, Curbralan Ltd., kevlin@curbralan.com , July 2000

    The following occurred to me as a way of avoiding passing function pointers around or running into the stream type problems you describe:

    #include <iostream>

    using namespace std;

    template<typename derived>
    class manip
    {
    public:
            template<typename out_stream>
            out_stream &operator()(out_stream &out) const
            {
                    return (*static_cast<const derived *>(this))(out);
            }
    };

    class mendl : public manip<mendl>
    {
    public:
            explicit mendl(size_t how_many)
            : count(how_many)
            {
            }
            template<typename out_stream>
            out_stream &operator()(out_stream &out) const
            {
                    for(size_t line = 0; line < count; ++line)
                    {
                            out.put(out.widen('\n'));
                    }
                    return out;
            }
    private:
            size_t count;
    };

    template<typename out_stream, typename manip_type>
    out_stream &operator<<(out_stream &out, const manip<manip_type> &op)
    {
            return op(out);
    }

    It is possible to factor out one_arg_manip, two_arg_manip, etc classes, but for brevity and generality, the code above seems to work fine.

     
     

      © Copyright 1995-2005 by Angelika Langer.  All Rights Reserved.    URL: < http://www.AngelikaLanger.com/IOStreams/forum.htm  last update: 16 Aug 2005