Doc. no.: N1901=05-0161 Date: 2005-10-14 Project: Programming Language C++ Reply to: Matt Austern <[email protected]>
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.
Most of the entries in the wish list fall into a small number of general categories:
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.
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.
Requester: Bjarne Stroustrup
Paper:
String versions of all (or) most functions that take C-style strings (e.g. filestream constructors)
Requester: Bjarne Stroustrup
Paper:
Simple functions for extracting int and floating-point values out of a string
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:
Requester: Bill Kempf, Bjarne Stroustrup, Andrei Alexandrescu, others
Paper:
Requester:Bjarne Stroustrup
Paper:
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.
Requester: Bjarne Stroustrup
Paper:
Requester: Bjarne Stroustrup, Hans Boehm
Paper:
"Infinite precision" reals.
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.
Requester: Bjarne Stroustrup
Paper:
a facility for random-access to files; maybe a form of random-access iterators for filestreams
Requester: Bjarne Stroustrup
Paper:
a range checked version of standard containers/iterators and algorithms
Requester: Bjarne Stroustrup, Beman Dawes
Paper:
a way of manipulating files that are part of a directory structure
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.
Requester: Bjarne Stroustrup, Tanguy Fautré, Sunil Palicha
Paper:
a good linear algebra library (Matrices and vectors)
Requester: David Miller
Paper:
Versions of the standard containers with virtual destructors
Requester: Howard Hinnant
Paper:
Move semantics, which requires core and library support
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.
Requester: Gary Powell
Paper:
A container to hold anything, like dynamic_any
Requester: Gary Powell
Paper:
A date/time library, a date is not a duration! And an end to time_t.
Requester: Gary Powell
Paper:
a graph library, aka boost/graph (supplements std containers)
Requester: Gary Powell
Paper:
math/octonion & math/quaterion's (used by game designers for 3d math.)
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.
Requester: Matt Austern
Paper:
New STL algorithms: copy_if, is_sorted, versions of the uninitialized_* algorithms that take allocator arguments.
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.
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.
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.
Requester: Rüdiger Brünner, John Medema, Eduardo Yánez
Paper:
Generic database support; STL-based recordset operations
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.)
Requester: Rüdiger Brünner
Paper:
Fixed-point arithmetic library and currency class based upon it
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.
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.
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)?
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.
Requester: Diego Bragato
Paper:
A standardized documentation facility (e.g. doxygen)
Requester: Diego Bragato
Paper:
A metadata language support (e.g. xdoclet,jdk1.5)
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
Requester: Diego Bragato
Paper:
Support for the design by contract method, including standardized support for testing available from the asserts in the contracts.
Requester: Diego Bragato
Paper:
Requester: Diego Bragato
Paper:
Specification for a web service container, taking into account also authentication
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:
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.
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); } };
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.
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.
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.
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.
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).
Requester: James Buchanan
Paper:
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.
Requester: Zach Laine
Paper:
The lack of uniformity between std::map iterators and other container's iterators could be partially addressed by providing "*_value" versions of std::for_each, std::accumulate, etc.. These versions would be specialized for iterators whose value_types are std::pairs, and would operate only on the .second member thereof, while still operating as before on iterators with non-std::pair value_types. Alternately, this could be accomplished by providing a new iterator that wraps a given iterator, and returns the wrapped iterator's value_type's .second member when dereferenced, if appropriate.
This lack of uniformity could be fully addressed by acknowledging that std::map is a bit different than the other containers, and creating a custom iterator type for its use. This new iterator type would still provide access to the key associated with its associated element, through a method called key_value() or similar, but would access its element's mapped value when dereferenced, and would access its element's mapped value's members using operator->().
Requester: Assaf Lavie
Paper:
To be able to open Unicode-named files using fstream (i.e. not just a string c'tor but also a wstring c'tor).
Requester: Assaf Lavie
Paper:
i.e. standard basic_string<tchar> where tchar compiles to either char or wchar_t
Requester: Assaf Lavie
Paper:
From Assaf Lavie:
I wish it was as easy to do web-stuff in C++ as it is in, say, perl. Classes for HTTP/FTP/HTTPS/XML/HTML/
From John Medema:
A unified socket/stream interface. Perhapsnstream nsck( "www.google.com:80", "#" )where "#" is a delimiter string for string parsing (i.e. the stream contains "1#2#3#4.4#5", and repeated calls nsck >> myString would yield myString values of 1, 2, 3, 4.4, and 5).
Requester: Assaf Lavie
Paper:
lambda expressions - std::for_each is harldy usefull without them.
Requester: John Medema
Paper:
Wrapper libraries for common C functions. This would be largely unnecessary if we could get a richer std::string interface with conversions to and from C data types, but there are a great many socket functions that need dynamically allocated pointers.
Requester: Greg Osgood
Paper:
I would like to see a binary_find function in STL algorithm which would work just like binary_search except instead of returning a bool indicating whether or not the item was found, would return an iterator to the object if it is found and the end of the collection if it is not. Just like binary_search, there should be two versions one which takes a predicate. The function signature could be as follows:
template<class ForwardIterator, class Type> ForwardIterator binary_find( ForwardIterator _First, ForwardIterator _Last, const Type& _Val ); template<class ForwardIterator, class Type, class BinaryPredicate> ForwardIterator binary_find( ForwardIterator _First, ForwardIterator _Last, const Type& _Val, BinaryPredicate _Comp );
Requester: Ravi Menon
Paper:
A
candidate for a boost version of intrusive containers
We have observed performance problems with std stl containers (it is used at certain areas in our code), and sticking with old C code (space and time efficient) is too cumbersome.
Without getting into ugly details, one main issue we see with stl containers like map and hash_map is the 'extra allocation' required for the node - _Hashtable_node for hash_map and _Rb_tree_node for map. Even if we are storing pointers to objects (for key and value) to avoid copy ctor overheads for the pair, for MT systems with mutex overhead, it still is an issue.
Although I am a big fan of stl containers, this is one criticism I can't overcome from folks who are more used to old C style intrusive implementations (with all that unsafe casts to void* etc..).
No amount of positive arguments in favor like type safety, inlining (as opposed to fn pointers used for hash comparators and hash functions), readability, s/w maintenance etc.. can overcome the bias in favor of measurable (and significant) performance gains with intrusive lists.
Requester: Ravi Menon
Paper:
It would be useful to have some provision (a template argument?) to supply an alternative hash table used for unordered associative containers. E.g. power of 2 size hash table to avoid mod (%) arithmetic, and get to the bucket via bit-wise '&' - i.e. bucket = hash & (size - 1). I can think of some designs and willing to contribute if there is an interest.
Please sent additions to this list to Matt Austern, matt @ lafstern.org