Doc. no.: N1901=05-0161
Date:     2005-10-14
Project:  Programming Language C++
Reply to: Matt Austern <austern@google.com>

C++0x Standard Library wishlist (revision 5)

This is a list of suggested additions to the standard C++ library for the next version of C++ ("C++0x").

This list is intended as a stimulus to further work. Some of the items on this list already have one or more concrete proposals associated with them, others are vague hopes, and most are somewhere in between. Similarly, the scope of these items extend from minor changes in an existing interface to major research projects.

I have listed a name or names for each item, and, if relevant, I have listed a paper or papers describing the idea. These ideas are not necessarily supported by anyone other than the person who suggested them, and you should not assume that any particular item will make it into C++0x. The items in this list are in no particular order.

Categories

Most of the entries in the wish list fall into a small number of general categories:

The wish list


Formatted container output

Requester: Dave Abrahams
Paper:

Simple and uniform display mechanism for arbitrary ordered lists. (Arrays, STL containers, pairs, tuples, etc.) cout << x should "just work" for such types.


Infinite-precision integer arithmetic

Requester: Maarten Kronenburg, Bjarne Stroustrup, Matt Austern, others
Paper: N1718, "A Proposal to add the Infinite Precision Integer and Rational to the C++ Standard Library", M. J. Kronenburg.


Uniform use of std::string

Requester: Bjarne Stroustrup
Paper:

String versions of all (or) most functions that take C-style strings (e.g. filestream constructors)


Simple numeric access

Requester: Bjarne Stroustrup
Paper:

Simple functions for extracting int and floating-point values out of a string


A richer std::string interface

Requester: Frank Yeh, John Medema, and others.
Paper:

Better member functions in string template class eg. trimming, upper/lower case conversion etc. Some specific suggestions:


Threads

Requester: Bill Kempf, Bjarne Stroustrup, Andrei Alexandrescu, others
Paper:


Sockets

Requester:Bjarne Stroustrup
Paper:


Explicit support for Unicode

Requester: Matt Austern, Assaf Lavie
Paper:

Assaf Lavie adds: Text encoding libraries - all formats of Unicode and code page conversions, base64 (maybe through iostream manipulators), etc.


An XML parser and generator library

Requester: Bjarne Stroustrup
Paper:


Constructive reals

Requester: Bjarne Stroustrup, Hans Boehm
Paper:

"Infinite precision" reals.


GUI

Requester: Bjarne Stroustrup, John Medema, others
Paper:

Some form of simple graphic/GUI library (possibly a simple interface to the simpler parts of larger libraries)—a recurent theme.


Random access to files

Requester: Bjarne Stroustrup
Paper:

a facility for random-access to files; maybe a form of random-access iterators for filestreams


Safe STL

Requester: Bjarne Stroustrup
Paper:

a range checked version of standard containers/iterators and algorithms


Filesystem access

Requester: Bjarne Stroustrup, Beman Dawes
Paper:

a way of manipulating files that are part of a directory structure


Process manipulation

Requester: unknown
Paper:

Process manipulation library—allows you to iterate processes running on the system and its threads, support forking, duping a process, killing etc.


Linear algebra

Requester: Bjarne Stroustrup, Tanguy Fautré, Sunil Palicha
Paper:

a good linear algebra library (Matrices and vectors)


Virtual destructors for containers

Requester: David Miller
Paper:

Versions of the standard containers with virtual destructors


Move semantics

Requester: Howard Hinnant
Paper:

Move semantics, which requires core and library support


String formatting

Requester: Gary Powell
Paper:

A string formatting library. (Aka, type safe printf) John Bates suggests that one way to improve on printf would be to have explicit parameter substitution via numbering, as opposed to the implicit ordering in printf. This would be similar to Java's MessageFormat object or Microsoft's FormatMessage API and would allow better internationalization support.


Runtime generic container

Requester: Gary Powell
Paper:

A container to hold anything, like dynamic_any


Date and time

Requester: Gary Powell
Paper:

A date/time library, a date is not a duration! And an end to time_t.


Graph algorithms

Requester: Gary Powell
Paper:

a graph library, aka boost/graph (supplements std containers)


Quaternions and octonions

Requester: Gary Powell
Paper:

math/octonion & math/quaterion's (used by game designers for 3d math.)


Units

Requester: Gary Powell, Walter Brown, Andy Little
Paper:

a SI/Units library. ( e = m c2, and end to the mars lander crashes.)

One example of work in this area is Andy Little's pqs library, which addresses physical quantities as well as units.


More STL algorithms

Requester: Matt Austern
Paper:

New STL algorithms: copy_if, is_sorted, versions of the uninitialized_* algorithms that take allocator arguments.


Web services

Requester: Jonathan Schilling
Paper:

A SOAP- and XML-based web services binding to the standard library. There would also need to be some kind of metalanguage/directives mechanism for marking within the C++ source, which classes and functions are being exposed as web services.


More special functions

Requester: Paul Bristow
Paper: N1668 = 04-0108, "A Proposal to add Mathematical Functions for Statistics to the C++ Standard Library", Paul Bristow

More math functions for statistics: Student's t function, Kolmogorov statistic, incomplete beta function, digamma function, and so on.


Full-width integer operations

Requester: Matt Austern
Paper:

A mechanism for accessing integer operations that every processor has: addition with carry, full-width multiplication, and division with remainder and quotient. The signatures might look something like this: pair<UInt, bool> add(UInt, UInt);, pair<UInt, UInt> mult(UInt, UInt);, pair<UInt, UInt> div(UInt, UInt);. We would probably want overloads for unsigned int, unsigned long, unsigned long long (assuming it's added to the core language), and maybe unsigned char.


Database support

Requester: Rüdiger Brünner, John Medema, Eduardo Yánez
Paper:

Generic database support; STL-based recordset operations


Serialization

Requester: Rüdiger Brünner, Raffaele Mancuso, others
Paper:

Library for binary object serialization/deserialization including object factory, versioning support, support for native datatypes and Standard Library classes (std::basic_string, STL containers, std::complex, etc.)


Fixed-point arithmetic

Requester: Rüdiger Brünner
Paper:

Fixed-point arithmetic library and currency class based upon it


Patterns

Requester: Rüdiger Brünner, Assaf Lavie
Paper:

Singleton template (like in the Loki library) and probably also generic implementations of other common patterns. Assaf Lavie adds a request for machine-wide singleton classes.


Interval arithmetic

Requester: Sylvain Pion
Paper:

The Sun compiler provides a built-in type for interval arithmetic, and Boost and CGAL have interval classes. There are many other implementations elsewhere.


Class factory implementation

Requester: Alisdair Meredith
Paper:

One item I would like to add to the LWG wish list if a 'class factory' or 'virtual constructor' implementation, again inspired by Loki. I have been wrestling with several points of the design space, trying to find the best balance. Was hoping to propose something for TR2 but there is one issue that really needs core (i.e. Evolution) support before we can have a truly satisfying interface, and that is the ability to work with any constructor rather than just the default.

A mix of perfect forwarding and var-arg template parameters will get us some way there, but I'm still not sure it is enough.

Another issue not immediately tied in is the progress on dynamic libraries, as class factories often lie at the heart of plug-in schemes.

Beyond that it is a matter of defining the optimal interface. The Loki version is quite policy driven eg. for return type. Do we want to allow a variety of returns, or fix on tr1::shared_ptr, or auto_pr (or even move_ptr if it arrives)?


Full support for user-defined memory models

Requester: Dmitriy Morozov and others
Paper:

The standard's allocator machinery, in principle, allows users to define allocators with alternate memory models. (The original motivation was MS-DOS's "near" and "far" memory models.) Allocators have reference and pointer typedefs. However, this support is seriously limited. First, the current standard doesn't allow any freedom for Alloc::reference: it is required to be T&. Second, 20.1.5/4-5 says that standard library implementations are allowed to ignore an allocator's memory model typedefs and assume that all allocators use the usual memory model.

These restrictions should be removed. This may require some core language changes. It may also require writing out requirements that an alternate memory model must satisfy.


Documentation mechanism

Requester: Diego Bragato
Paper:

A standardized documentation facility (e.g. doxygen)


Metadata support

Requester: Diego Bragato
Paper:

A metadata language support (e.g. xdoclet,jdk1.5)


Design paradigms

Requester: Diego Bragato
Paper:

Support for reversibility from the implementation to a "set of" design paradigms (e.g. UML and eiffel). I do feel that this would be a strong innovation. This feature can be nicely integrated with graph support, documentation, metadata, and even the graphical facilities


Design by contract

Requester: Diego Bragato
Paper:

Support for the design by contract method, including standardized support for testing available from the asserts in the contracts.


Aspects

Requester: Diego Bragato
Paper:


Web service container

Requester: Diego Bragato
Paper:

Specification for a web service container, taking into account also authentication


map and reserve

Requester: Liran Shaul
Paper:

Why doesn't the std::map class offer a method reserve that will allocate memory ahead of time, like the vector::reserve function?

I understand that this function won't be able to be as efficient as the vector/list matching function, However allocating all the memory (or at least most of it) In advance has 2 major advantages that I can think of:

  1. one big call to the new operator is probably better then many small memory allocations
  2. In case that there is not enough memory, it is probably better to know about it In advance then starting to enter items into the map, just to discover later that there is not enough memory in the system to hold a map that big.

Atomic operations

Requester: Jeremy Jurksztowicz, James Buchanan, Lubos Dolezel, and others.
Paper:

I was just going over the wishlist for the C++ standard and have another suggestion. As lock free programming comes more and more into mainstream, why not add an atomic type to C++? Something like 'volatile word', 'atomic<T>' or just make it a requirement that all accesses to volatile ints are atomic, for most common platforms it already is. This would make portable FIFO, and other lock free structure implementations trivial. Alternatively you could add a std::compare_and_swap function.

James Buchanan adds a request for mutexes, semaphores, and spinlocks. This would be enough for low level system programming on SMP machines.

Lubos Dolezel adds: Something like std::mutex would be great. Just a simple multiplatform class for mutexes with methods like lock(), unlock() and trylock() would simplify many projects.


Container-based algorithms

Requester: Kirk Korver
Paper:

One of the annoyances I have with using the STL is it's implementation of std::for_each(). I think this algorithm is a great idea, and passing in the start and end ranges are nice for flexibility. But I ask you, how many times have you used for_each on EVERY ELEMENT in the collection? I would wager that it is upwards of 90%. Why do so much typing for something we do often?

I propose: The addition of the algorithm for_all, which is a replacement to for_each, where the functor is to be applied to ALL elements in the collection.

Here is the actual implementation I have in my code.

namespace std
{
    // Author & Date:   Kirk Korver     03 Jun 2004
    // Purpose: wrap the std::for_each function to apply the functor to ALL entries
    // Inputs:
    //  c - the container we care about
    //  f - the function or functor we want to apply
    template <class Container, typename Functor> inline
    Functor for_all(Container  & c, Functor & f)
    {
        return std::for_each(c.begin(), c.end(), f);
    }
};

Control over containers' threading model

Requester: Greg Osgood
Paper:

There is one feature that I would like to see added to the STL: the ability to specify the threading model for collections. In most implementations the threading model is defined at the project level. There are some situations in which accessing a collection if very critical to performance of the application. If the threading model is single threaded then the performance will be very close to the same as using arrays. However, if the threading model is multithread then the performance may suffer greatly. This seems pretty obvious to me, but if you have any questions or need clarification let me know.


More convenient way of deallocating vector memory

Requester: Tyler Doubrava
Paper:

It would be great if std::vector<> had an intuitive way to deallocate its memory. You can do so by calling the member function swap(), providing an empty instance of the same type. Most people, I believe, would have intuitively expected the clear() member function to do so.

I suggest adding a new member function, dealloc() which would call clear, and free the vector's memory.


Lexical analysis and parsing

Requester: Benjamin Hanson
Paper: lexertl: The Modular Lexical Analyser Generator

I would like to see a lexical analyser class (and maybe even a yacc class) added to std::tr2. The easiest way to see the kind of design I have in mind is to look at http://www.benhanson.net/lexertl.html (I am the author). I am aiming to eventually produce a good enough version that would be accepted by Boost, but I would be perfectly happy to see someone else do a better job and faster than I can!

James Buchanan adds:

Spirit is very nice, but is quite hackish. I think it's better to have some kind of template where you can choose the algorithm (LL(k)/resursive descent, GLR, LALR, LR(k)) and make the lexical analysis and parsing framework understand EBNF as a standard way for feeding in a CFG. Also, there should be additional types like symbol tables and an AST type.

Graphics library

Requester: James Buchanan
Paper:

Some kind of standard interface for dealing with graphics primitives (hooks into X or ncurses/dialog on Unix systems, or optionally SVGAlib on Linux, Win32 on Windows systems, whatever on Mac).

Also multimedia: A standard interface to the audio and video facilities on a platform.


Trees

Requester: James Buchanan
Paper:

Binary trees, splay trees, Red-Black trees, B trees, B+ trees, dancing trees (those used in Hans Reiser's Reiser File System).


Data compression

Requester: James Buchanan
Paper:


Better support for embedded programming

Requester: James Buchanan
Paper:

This would be separate from the Standard C++ library proper, and become a second standard library. There is a draft of C for embedded systems that the embedded C++ stdlib could make use of as a starting point. The embedded stdlib would need to have interfaces for access to low-level system I/O (inport_b, outport_b and friends), etc.


Specialized iterators and/or algorithms for map iterators

Requester: