Posts: 32 / Nickname: cda / Registered: February 11, 2003 0:06 PM
Your C++ Wish List
September 25, 2004 8:00 PM
|
C++0x is under construction. Get your licks in while there's still time.
http://www.artima.com/cppsource/wishlist.html |
Posts: 1 / Nickname: impatient / Registered: November 11, 2003 7:24 AM
Re: Your C++ Wish List (Editorial)
September 27, 2004 7:36 AM
|
I don't know if I read the wish list well but I didn't see
anny mentioning of the following in the requests for enhancements to the STL: -- Smart pointer objects (See Josuttis' book or look at the boost library cases) -- HASH containers... come on this one is a must! And also, can someone appoint some people that actually program in C++ to that commision. That would make a difference as most practical issues are usually ignored in order to get some theoretical perfection that is never reached. |
Posts: 32 / Nickname: cda / Registered: February 11, 2003 0:06 PM
Re: Your C++ Wish List (Editorial)
September 27, 2004 7:29 PM
|
Actually, the two items you mention are very high in the list. The Boost smart pointers are the basis for what is now being discussed for C++0x. Also, a hash table proposal is being reviewed, so, you're in good company!
|
Posts: 1 / Nickname: oldtimer / Registered: September 27, 2004 6:11 PM
Re: Your C++ Wish List (Editorial)
September 27, 2004 10:30 PM
|
>11. Extended type information (as much runtime type information as possible for a compiled language)
I guess this would cover introspection (by applying this extended type information to instances). I would add to this: arbitrary user-created meta data for all constructs. I know this isn't an easy one, but getting something anywhere towards this ideal would be really great. It's a feature that helps make introspection really useful. For example, when pushing introspection to do persistence, GUI editing, report making, etc. Arbitrary meta data lets you mark up the classes/fields with all sorts of things like a description, or a read-only marker, or marking things as primary state vs derived state, or setting policies for GUI editing (like to say that this Vector2 is a position in the space defined by _that_ transform). I'm a die hard C++ programmer, but after working with C# for a bit, I found myself wishing C++ could do this. I know it's not fashionable for C++ to add features that "C++ replacement languages" have, but let's just say we are inspired by lisp or something... |
Posts: 1 / Nickname: tbentrup / Registered: September 27, 2004 11:26 PM
Re: Your C++ Wish List (Editorial)
September 28, 2004 3:58 AM
|
I like templates and use them frequently and the most libraries are based on them too, but what I miss is the possibility to define templates with an unknown number of parameters.
The BOOST tuple class or signal/slot classes or many others use copy & paste (or the preprocessor) and they are all limited to a fixed maximal count of parameters (e.g. 3 or 5 or 10). It would be nice, if C++ could itself construct templates with any number of parameters (as '...' in printf()). extensions to C++: - '...' in templates - '##' is the number of '...' parameters (N) - '#' iterates over all the parameters (1 - N) examples:
I know this is hard work for compiler vendors but this would replace many copy & paste code and fewer use of the preprocessor. I would also appreciate, if the header guards (with "#ifdef") could be replaced by another command (e.g. "#pragma once" like some (but not all) vendors do - I know that this is another pp-command, but easier to use). |
Posts: 1 / Nickname: cocus / Registered: September 30, 2004 2:26 AM
Re: Your C++ Wish List (Editorial)
September 30, 2004 6:30 AM
|
I would hop for templated typedefs as a means to alias template names. THis greatly would faciliate metaprogramming and would also make C++ more consitent.
|
Posts: 1 / Nickname: stheller / Registered: October 6, 2004 10:07 AM
Re: Your C++ Wish List (Editorial)
October 6, 2004 2:11 PM
|
I would like some language/library support for an automatic way to use polymorphism without needing to expose pointers/memory management to the application program. I have developed ways to do this, based on the Coplien "envelope/letter" idiom, but more convenient and flexible. From my experience, I'm pretty sure that many other C++ developers could benefit greatly from support for such a feature, as it is far from obvious how to implement it unless you have seen it before.
|
Posts: 1 / Nickname: jgh / Registered: October 7, 2004 7:13 AM
Re: Your C++ Wish List (Editorial)
October 7, 2004 11:15 AM
|
No need to be bashful. Can you give us a taste of what you're referring to?
|
Posts: 1 / Nickname: stephan / Registered: October 8, 2004 8:40 AM
Re: Your C++ Wish List (Editorial)
October 8, 2004 1:33 PM
|
A couple things I would really like to see supported:
1- Exception reporting. I realize debug info is compiler specific; but it'd be so darn usefull if there was a standardized way of reporting where the exception was thrown (not caught). This should include the filename, the line number, and the call stack. 2- Better support for pointers to functions and methods (functors and closures). Specifically, it sould be possible to have a variable point to any of: Base::Method(), Derived::Method() (no contravariance), or ::GlobalFunction() if they have the same parameters. Borland C++Builder supports this with the __closure keyword extension. I also wrote a template class using partial parameterization; but I shouldn't have to. That's my wish list. Stephane |
Posts: 2 / Nickname: arkadiy / Registered: July 2, 2004 6:38 AM
Re: Your C++ Wish List (Editorial)
October 12, 2004 0:01 PM
|
- typeof would be handy (and AFAIK, some form of it is considered). If nothing else, it would greatly improve syntax of all the stuff related to expression templates.
- Another thing that comes to mind is that much of template meta-programming that we are doing now looks very much as hacking. Instead of asking the compiler for certain information, we apply some action, as to a black box, and watch how it reacts. And then we make decisions based on these reactions (consider SFINAE). Instead of that, compilers could expose some kind of an "object model", available at compile time, in the similar fashion IE exposes its DHTML. We would be able to ask the compiler which classes have been defined, which templates instantiated, what is the type of this particular expression (typeof), whether a class has a certain typedef, etc. At the same time we could drive the compilation process by writing to this "object model", e.g., create compile-time variables, undefine classes, etc. - One more "complain": although C++ has rules regarding cross-unit compilation (ODR), there appears to be no "tools" that could act across compilation units, everything gets reset. - An ability to define an entity in a namespace other then the current context, such as: namespace A { class ::B::MyClass { }; } would allow to wrap a class and corresponding specialization (trait) into a macro... - non-deducable context... Is it really necessary? Why not be able to specialize on vector<T>::const_iterator? Regards, Arkadiy |
Posts: 1 / Nickname: p4dd4 / Registered: October 23, 2004 2:20 PM
'uint' ?
October 23, 2004 6:37 PM
|
This is petty but, with the STL using
unsigned int for its size() s, if you want to be anal you have to use unsigned to avoid signed/unsigned mismatch es. Typing (keyboard kind) unsigned is slower than int - how about uint as an alias? Or is that included in the new <inttypes.h> ?
|
Posts: 32 / Nickname: cda / Registered: February 11, 2003 0:06 PM
Re: 'uint' ?
October 24, 2004 7:28 PM
|
> This is petty but, with the STL using
unsigned for its size() s, if you want to be> anal you have to use unsigned to avoid> signed/unsigned mismatch es. Typing (keyboard> kind) unsigned is slower than> int - how about uint as an> alias? Or is that included in the new > <inttypes.h> ?Actually, it uses "size_t", doesn't it? This is much more typable than "unsigned int". There has been some talk about considering adopting the new integer type names from C99, which would cover your request, but I don't know where that discussion is at. |
Posts: 2 / Nickname: ggc / Registered: October 24, 2004 9:00 AM
Re: Your C++ Wish List (Editorial)
October 31, 2004 5:23 PM
|
(1) Consider making a statement about what kinds of memory models C++ will support.
Example: I have been involved a number of projects in which multiple processes had their own static spaces, but all had access to a shared arena. It seems the world is moving away from this, toward the multi-threaded model, in which every thread has the same static space. I don't have a problem with this move. But consider: I could make an STL container accessible to all processes by putting it in the shared arena and giving it a shared-memory allocator. However, I cannot use the Boost shared_ptr in this context, since it does dynamic allocation, but does not allow me to specify an allocator.I am not saying the Boost shared_ptr is "bad" (on the contrary, I think it is very much needed). I am saying that we need to think about things like this. Do we intend to support every memory model under the sun? If so, then any shared_ptr that gets added to the Standard Library needs to allow specification of an allocator. If not, then we should make a explicit statement about what memory models the Standard Library is intended to support.(2) More generally, be careful about introducing possible system dependencies into the Standard Library. The "C++0x Standard Library Wishlist" includes: 5. A threads library 6. A socket library 10. Some form of simple graphic/GUI library All of these (and possibly some others on the list) will tend to make C++ favor certain kinds of systems above others. Again, I do not have a problem with this. I do have a problem with adding these things without careful consideration and explicit statements of intent. (3) Include the Boost random number library. Isn't everyone tired of cruddy pseudo-random number generators? (4) Some thoughts on octonions and quaternions: From the "C++0x Standard Library Wishlist": 21. Math/octonion & math/quaternions (used by game designers for 3d math) Octonions are a mere curiosity, to be exhibited in the occasional advanced math class. No one uses them for anything practical. Certainly no game designer does anything with them. Quaternions, on the other hand, certainly are useful, being a good basis for computations involving 3-D rotations and orientations. However, the Boost quaternion package, while it is a top-notch implementation, is a mathematician's idea of a quaternion package, not a game designer's. The mathematician thinks the trig functions and the multipolar representation are great, but the game designer will never use them. The game designer wants quaternions that interact well with 3-D vectors. For example, it seems silly to have to write quaternion<double>(0., v[0], v[1], v[2]); when what I really want is something like quaternion<double>(0., v.begin()); I suggest adding a constructor that, as above, takes a floating-point value and an input iterator. Similarly, add a version of quaternion<T>::unreal that takes an output iterator and sends its i, j, & k values to wherever the iterator points.(5) Lastly, for goodness sake, specify std::sort to be O(n log n).The committee knows that already, right? |
Posts: 1 / Nickname: podian / Registered: October 8, 2004 7:18 AM
Re: Your C++ Wish List (Editorial)
October 8, 2004 11:21 AM
|
What about synchronized keyword to synchronize the whole method (like Java)? This will ensure that programmers do not forget to unlock a semaphore when they return from a middle of a function.
|
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: Your C++ Wish List (Editorial)
October 9, 2004 5:39 AM
|
There is already a better mechanism for automatic resource cleanup. Take a look at this article:
http://www.hackcraft.net/raii/ |
Posts: 2 / Nickname: peterz / Registered: November 1, 2004 9:57 PM
Re: Your C++ Wish List (Editorial)
November 2, 2004 3:08 AM
|
This can already be done quite easily with scoped lock guards using the resource acquisition is initialization. The only reason Java has this IMHO language hack (and the 3-state try/catch/finaly) is that is has no scope bound destructors.
The added advantage of doing this inside the language is that it can be used custom lock types not only some primitives. |
Posts: 2 / Nickname: peterz / Registered: November 1, 2004 9:57 PM
Re: Your C++ Wish List (Editorial)
November 2, 2004 3:19 AM
|
My top list of want to haves are:
- template typedefs; - auto type. per illustration:
and
|
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: Your C++ Wish List (Editorial)
October 1, 2004 8:39 AM
|
1. "Controlled virtuality" - like in C# or (even better) C++/CLI. Right now, if you declare a function virtual in a parent class, virtuality will automatically be inherited even if it is not really needed. For instance:
struct IMyInterface { virtual void fun() = 0; }; struct MyImplementation { void fun(); // this one is also virtual }; In order not to break existing code, maybe it would be a good idea to add a keyword that would "stop" a function from being virtual: struct MyImplementation { nonvirtual void fun(); // this one is not virtual }; 2. XML API. I agree we need a good XML API. However, I would strongly suggest to avoid DOM which is non-efficient and not "C++ friendly". Some cursor-based model would be much better, IMHO. |
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: Your C++ Wish List (Editorial)
October 1, 2004 8:41 AM
|
Of course, I meant:
struct MyImplementation : IMyInterface { void fun(); // this one is also virtual }; |
Posts: 3 / Nickname: cdutton / Registered: July 20, 2004 9:25 PM
Re: Your C++ Wish List (Editorial)
October 2, 2004 1:42 PM
|
How about templated namespaces?
|
Posts: 32 / Nickname: cda / Registered: February 11, 2003 0:06 PM
Re: Your C++ Wish List (Editorial)
October 3, 2004 7:14 AM
|
> How about templated namespaces?
Could you elaborate on that? |
Posts: 3 / Nickname: cdutton / Registered: July 20, 2004 9:25 PM
Re: Your C++ Wish List (Editorial)
October 4, 2004 11:40 PM
|
> > How about templated namespaces?
> > Could you elaborate on that? I'm not entirely sure I can. By that I mean that I can't foresee all of the side-effects it might have, or weird and possibly uncouth ways in which such a thing might be used. I do seem to remember at leat a few projects which involved creating numerous templated classes where it seemed every template was using the same information. Rather than specifying that information for each object I used, and thus potentially screwing it up in numerous places, it would have saved a fair amount of time if I had been able to apply that template to the namespace I had wrapped all of those classes in. |
Posts: 8 / Nickname: essennell / Registered: September 7, 2004 10:19 PM
Re: Your C++ Wish List (Editorial)
October 5, 2004 6:28 AM
|
> Rather than specifying that information for each object I
> I used, and thus potentially screwing it up in numerous > places, it would have saved a fair amount of time if I had > been able to apply that template to the namespace I had > wrapped all of those classes in. Hmmm. Given that a namespace can be re-opened in several source files, this would place a bit of a burden on other people populating that NS. I don't see it would save you much. template< typename T > namespace X { class Z { }; } using X< int >::Z; How do you get an object of type Z? Z< int > z; //or Z z; You lose ease of understanding for ease of typing. |
Posts: 4 / Nickname: nesotto / Registered: December 10, 2003 1:42 AM
Re: Your C++ Wish List (Editorial)
November 2, 2004 9:12 AM
|
> > Rather than specifying that information for each object
> I > > I used, and thus potentially screwing it up in numerous > > places, it would have saved a fair amount of time if I > had > > been able to apply that template to the namespace I had > > wrapped all of those classes in. yeah, just think of the <algorithm> header. A lot of template argument list are exactly the same. I think templated namespaces might fit well together with Carl Daniel's proposal about class namespaces. -Thorsten |
Posts: 1 / Nickname: quiark / Registered: October 26, 2004 8:02 AM
Re: Your C++ Wish List (Editorial)
October 26, 2004 0:06 PM
|
Where are class properties (those things which replace calling getter/setter methods in user code)? They are often used in many languages and even some C++ extensions have them, but I'v e seen no remark on them.
|
Posts: 2 / Nickname: ggc / Registered: October 24, 2004 9:00 AM
Re: Your C++ Wish List (Editorial)
October 31, 2004 5:44 PM
|
> Where are class properties (those things which replace
> calling getter/setter methods in user code)? I think this is a great idea, in principle, but I'm a little hazy about how to implement it so that it fits well into C++. First, are we talking about the same thing. I figure we let something like cout << x.my_prop; be translated into something like cout << x.my_prop_get(); And this x.my_prop = 3; turns into something like x.my_prop_set(3); So far so good? Now, what should we do with this: x.my_prop += 5; Do we really want it to become this: x.my_prop_set(x.my_prop_get() + 5); That works in (say) Python, but in C++ operator+= is supposed to be efficient. Okay, so we allow umpteen different setter methods to handle all the assignment operators. Now what about this: void foo(int & i) { i = 7; } foo(x.my_prop); Do we want this to work at all? How is it going to happen? With a proxy class? Those can let you down; remember std::vector<bool> ?> They are > often used in many languages and even some C++ extensions > have them, but I'v e seen no remark on them. I am not familiar with class properties in any C++ extension. Do any of the ones you know about provide good solutions to the problems pointed out above? |
Posts: 32 / Nickname: cda / Registered: February 11, 2003 0:06 PM
Re: Your C++ Wish List (Editorial)
November 1, 2004 7:05 PM
|
[About Properties]
FWIW, Microsoft's new C++ for the Whidbey release implements properties similar to the way C# does. It seems pretty reasonable. |
Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
Re: Your C++ Wish List (Editorial)
November 2, 2004 1:30 PM
|
I tried your sample with Borland's C++ Compiler, version 5.5:
#include <iostream.h> class PropTest { private: int someprop; int get_SomeProp() { return someprop; } void set_SomeProp( int value ) { someprop = value; } public: PropTest() { cout << "Hello world!" << endl; } ~PropTest() { cout << "Goodbye world!" << endl; } __property int SomeProp = {read = get_SomeProp, write = set_SomeProp }; }; void foo( int & i ) { i = 7; } void main() { PropTest pt; pt.SomeProp = 88; cout << "SomeProp is " << pt.SomeProp << endl; foo( pt.SomeProp ); cout << "SomeProp is " << pt.SomeProp << endl; } And the output seems to indicate that it worked fine: Hello world! But that is only because I used a very simple case. If I did something more realistic, involving a calculated value, like this: #include <iostream.h> class PropTest { private: int seconds; int get_Minutes() { cout << " --> get_Minutes()" << endl; return seconds / 60; } void set_Minutes( int value ) { cout << " --> set_Minutes(" << value << ")" << endl; seconds = value * 60; } public: PropTest() { cout << "Hello world!" << endl; } ~PropTest() { cout << "Goodbye world!" << endl; } __property int Minutes = {read = get_Minutes, write = set_Minutes }; }; void foo( int & i ) { i = 7; } void main() { PropTest pt; pt.Minutes = 88; cout << "Minutes is " << pt.Minutes << endl; foo( pt.Minutes ); cout << "Minutes is " << pt.Minutes << endl; } The results are: Hello world! Anyway, the moral is that reference variables in C++ throw a monkey wrench into the works. That makes sense, since you could also pass a read-only property by reference. I think the answer is that, in addition to adding properties, the specification would also have to add some rules, such as not allowing properties to be passed by reference. That isn't an unreasonable thing, probably. It seems like a property would have a special kind of "const-ness" (especially a read-only property). Another thing the Borland compiler did is allow you to create and use Delphi objects in C++, but in order to do this, you are forced to always create them on the heap (with new ). At first that seems really annoying and stupid, but it is better than not having the use of some handy objects. The reason I bring this up is to point out that properties would be worth having, even if some limitations were put on them.
|
Posts: 20 / Nickname: bigboy / Registered: June 14, 2004 10:43 AM
Re: Your C++ Wish List (Editorial)
November 2, 2004 2:02 PM
|
Not wanting to pump my own sales (/sails?) - I've been hanging fire hoping one of my friends would save me from appearing to do so (eh, Chuck! ;)) - but in chapter 35 of my new book Imperfect C++ (http://www.imperfectcplusplus.com/) I show how Properties - method & field, internal and external - can be implemented in C++. It provides 100% space efficiency for all property types, and 100% space efficiency for internal property types (where the property "member" contains the data for which it acts). For external properties, it has a maximum 1-byte space cost for all property members combined, and even this can be avoided if the class has any POD type members.
It uses a ubiquitous, at least as far as the 8 compilers I have tested it on (Borland, CodePlay, CodeWarrior, Comeau, Digital Mars, GCC, Intel, Visual C++), but non-standard facility for declaring a template's parameterising class type to be a friend, as described in http://www.cuj.com/documents/s=8943/cujexp0312wilson2/. The non-standard nature of it is a risk, to be sure, and I make no guarantees about future support for the facility, but having said that I'd be stunned if compiler manufacturers saw fit to remove it. Note that even the highly conformant Comeau compiler saw fit to add the --friendT command-line option to version 4.3.3 specifically in order to support this technique in --strict mode. For any of you who aren't moved to dash over to Amazon and buy a copy of Imperfect C++ to read about the technique, I am currently preparing an extract that describes the basis of it for an article for February's Dr Dobb's Journal. You might also take a peek into the stlsoft_method_properties.h and stlsoft_field_properties.h files, in the latest STLSoft (http://www.stlsoft.org/downloads.html) release.
|
Posts: 20 / Nickname: bigboy / Registered: June 14, 2004 10:43 AM
Re: Your C++ Wish List (Editorial)
November 2, 2004 2:03 PM
|
Gah!
"It provides 100% space efficiency for all property types" => "It provides 100% speed efficiency for all property types" Sorry about that ... |
Posts: 2 / Nickname: s11n / Registered: November 11, 2004 1:45 AM
Re: Your C++ Wish List (Editorial)
November 11, 2004 6:53 AM
|
This one may sound silly, but here it is:
Source code is the human interface to the language, and source code is edited in text editors. Most programming editors indent based on braces. The only reason i don't use deeply-nested namespaces in C++ (a-la Java) is because this indention gets unwieldy after 2-3 namespaces. Because source code is OUR interface to the language, i will propose a small amount of syntactic sugar to make it easier to nest namespaces without confusing editors: Current syntax and typical usage:
Suggested as an acceptable shortcut:
Easy enough to add to C++ parsers, i would think. The significance is that editors which indent only have one indention level to deal with, and also their syntax-highlighting code may not even have to change to deal with it. |
Posts: 2 / Nickname: s11n / Registered: November 11, 2004 1:45 AM
Re: Your C++ Wish List (Editorial)
November 11, 2004 9:09 AM
|
i wish... i wish... i wish...
For an in-language way to get the string form of a class' name. e.g., i'd love to see a well-defined-behaviour restriction placed on typeid::name(). Even if it didn't return "MyClassName", i'd like it to be forced to return some standardized representation of a type's NAME. To make this easier on compiler implementors, a type name should not include any type modifier info, like const, *, &, etc., as in a string context they are not normally significant (in my experience). |
Posts: 1 / Nickname: kinneym / Registered: November 14, 2004 4:06 PM
Re: Your C++ Wish List (Editorial)
November 14, 2004 9:09 PM
|
Probably a minor thing, but I would like to have the "substr" method on strings check for and handle strings that are out of bounds.
For instance, if I were to say something like this: string foo="Hello"; string bar=""; bar=foo.substr(bar,10,10); It should not give a run-time exception. It should merely set bar to "". (Just like awk, php and perl do!) |
Posts: 1 / Nickname: diegob / Registered: December 8, 2004 6:10 PM
Re: Your C++ Wish List (Editorial)
December 8, 2004 11:31 PM
|
I do say it from my side of enterprise programmer, and I'm not taking into account all problems related to HW architectures and platforms.
This is also a high level and demanding list, therefore it may go out of the boundaries of what it can stay within the actual timeframes and scoping. 1 A standardized documetation facility (e.g. doxygen) 2 A metadata language support (e.g. xdoclet,jdk1.5) 3 A draft Support for reversibility from the implementation to a "set of" design paradigms (e.g. UML and eiffel) This feature can be nicely integrated with graph support, documentation, metadata, and even the graphical facilities 4 Draft support for the design by contract method 5 A standardized support for testing availble from the asserts in the contracts 6 Aspects (e.g. aspects cpp) 7 A draft specification for a web service container, taking into account also authentication Kindly, Diego Bragato |
Posts: 1 / Nickname: cmd / Registered: December 16, 2004 4:06 AM
Re: Your C++ Wish List (Editorial)
December 16, 2004 9:14 AM
|
It's not my most important, or anything like it, but I haven't actually seen anyone else ever ask for it. It is trivial however.
Overloads of std::conj in <complex> for float, double and long double which simply return their argument, e.g. double std::conj(double x) {return x;} Why? So you can write a single template covering real and complex cases which involve conjugation. An inner product is a typical example, x * conj(y), which is x * y when real. You could argue the case for other complex-only functions in <complex> such as arg, but I've not needed those. conj I have. |
Posts: 1 / Nickname: clugston / Registered: December 20, 2004 9:37 AM
Re: Your C++ Wish List (Editorial)
December 20, 2004 3:15 PM
|
Add some support for delegation.
Ideally, something like Borland's __closure, but with support for static functions, with better integration into the type system, and with the full set of operations. ------------------------ Bare minimum proposal ------------------------ Modify section 5.2.10/9 to state that when a member function pointer(MFP) a of class X is converted using reinterpret_cast<> to another MFP b of a class Y __of incomplete type__ but the same signature, and a pointer p to X is converted to a pointer q to Y using static_cast<>, then invoking (q->*b)() is equivalent to (p->*a)(). This works on every C++ compiler ever made. It allows creation of optimally efficient delegates. Here's an example implementation: http://www.codeproject.com/cpp/FastDelegate.asp Unfortunately, this code is not legal (even though it works on all compilers, albeit with some nasty tricks for the non-standard MFPs used by Microsoft/Intel). But with that trivial change to the standard, it could be made legal retrospectively. The proposal has no side effects on other areas of the language. All extant compilers are automatically compliant. And it adds a significant new concept to the language. (In one of Herb's recent blogs, he mentioned that he drools over C# delegates. These are better, because they work with templates). I doubt you'll find anything with a better "bang for your buck". Of course it would be nice to have full language integration, especially with better error messages, and a defined ABI for delegate structures -- but please consider this kind of zero-cost option if a full implementation doesn't make the list. |
Posts: 1 / Nickname: handyman / Registered: January 3, 2005 7:33 AM
Re: Your C++ Wish List (Editorial)
January 3, 2005 0:48 PM
|
I have two requests:
[1] Allow underscores within (i.e., inside, not at the beginning) an integer literal to improve readability. See this thread in comp.lang.c++.moderated: Message-ID: <22868227.0411021649.97c19df@posting.google.com> [2] Raw string literals where back-slashes are just another character. E.g., r"This is a \n special string \t where there are no new lines or tabs" This would immensely help if C++ should be used for REs. thanks, - Anand |
Posts: 1 / Nickname: jadedhobo / Registered: January 3, 2005 7:44 AM
Re: Your C++ Wish List (Editorial)
January 3, 2005 0:57 PM
|
What I am missing in both list is improved/strongly typed enumerations. There have been some excelent proposals on comp.std.c++!
Personaly, I would also like the ability to extend an enumeration. Say for example that a base class contains an enum Base::color { r, g, b } then it is sometimes desirable to have enum Derived::color { Base::color, c, m ,y } in a derived class. |
Posts: 12 / Nickname: wkaras / Registered: December 22, 2003 2:53 PM
Re: Your C++ Wish List (Editorial)
January 4, 2005 7:41 PM
|
The ability to divide the public portion of a class's interface into named "subsets". Users of the subset would need an explicit statement indicating the usage. For example:
class A { public: ... // just plain public public X: ... // stuff in the X subset public Y: ... // stuff in the Y subset public X: ... // more stuff in the X subset }; void foo (A &a) { using class A::X; ... } class B { using class A::X; ... }; ********** In one large class heirarchy I worked with, there were a great many virtual function overrides that really just provided the value of a constant for some algorithm implemented in the base class, for example: class Quarter : public Coin { public: virtual int value(void) const ( return(25); } ... }; It would be clearer (and improve performance a bit) to be able to say: class Quarter : public Coin { public: virtual int Value = 25; ... }; The value of "Value" could be stored directly in the vstruct. The declaration: class Coin { public: virtual int Value; ... }; would make "Coin" abstract, since no value for "Value" is given. ********** A "psuedo-template" name footprint. The class footprint<A> would have the same size and alignment requirements as class A, but footprint<A> would have an vacuous implicit constructer and no other members. The purpose is this: union X { footprint<A> a; struct B b; footprint <C> c; }; X x; ... // Use x to store an A instance, constructed using // new placement syntax. new (&x.a) A; ********** In the same way that physicist are in need of a Unified Field Theory, I dream of a "Unified Meta-programming Mechanism" for C++. What I mean by this is some "thing" that would do everything that both templates and macros do and do it as well. For example, the "typeof" operator gives macros a fighting chance to act somewhat like function templates. Could a pre-processor with m4-type power and some set of "semantics-extraction" mechanisms (like typeof) take the place of templates? This is so brief and sketchy as to be useless. But maybe someone smarter than me can make something of it. |
Posts: 3 / Nickname: crusader / Registered: January 4, 2005 5:04 PM
Re: Your C++ Wish List (Editorial)
January 4, 2005 10:11 PM
|
http://groups-beta.google.com/group/comp.lang.c++.moderated/browse_frm/thread/747d3f2b3a82524a
Here I propose idea of template typedef along with its syntax and some neat features it will allow. Please note that this is not 'usual' template typedef, i.e. you can not do like this: template<class T> typedef foo<T, U>* foo2<T>; -> foo2<T> pVar; equivalent to foo<T, U>* pVar; instead it is a direct mirroring of typedef to the templates world. Also allowing forward declarations for type and template aliases will help! (or introduce implicit forwarding like in C#) Bye. Sincerely yours, Michael. |
Posts: 3 / Nickname: crusader / Registered: January 4, 2005 5:04 PM
Re: Your C++ Wish List (Editorial)
January 11, 2005 10:09 PM
|
Also It would be REALLY great to enforce "nothrow" guarantee on all std library exceptions, i.e. std::logic_error, std::runtime_error and so on. Currently only std::exception and std::bad_exception has this guarantee.
Due to this it is impossible to write true reliable application which uses STL functionality capable to throw library-defined exceptions. Bye. Sincerely yours, Michael. |
Posts: 3 / Nickname: crusader / Registered: January 4, 2005 5:04 PM
Re: Your C++ Wish List (Editorial)
January 11, 2005 10:19 PM
|
And once more:
time and date support is very sparse and ugly in C++ (mostly inherited from C). I'd like to have :) : 1. convenient datetime representation and conversion methods, e.g. to convert given local Sydney time to Egypt local time 2. support for any linear time axis, i.e. datetime wich is always increasing and difference between datetime always == time that passed between them. Currently only Atomic time has these features (AFAIK) and there are not so much systems around supporting this time. UTC can be used with clear explanations of "leap seconds issues". Also convenient conversion functions will be needed to convert this time to "usual human" time ("usual time" is our wall-clock time with all adjustments) and back with all ambiguities removed and clearly explained. Once I was developing real-time system that was meant to bve running for VERY long time, and I had a lot of "fun" due to crippled datetime support in C++ and even in underlying system. I believe C++ standard should enforce necessary rules upon platform to implement these features, or clearly describe how platform should emulate all or part of these rules. Bye. Sincerely yours, Michael. |
Posts: 1 / Nickname: jsyjr / Registered: January 21, 2005 2:39 AM
Re: Your C++ Wish List (Editorial)
January 21, 2005 8:38 AM
|
virtual const data members
Today a vtable is really an initialized static const struct containing only pointers to functions (plus possibly some opaque data used by the run time system). I would very much like to be able to declare and initialize members of types other than simply pointer to function. class C1 { // this single property costs a full pointer in the vtable virtual bool propertyX(void) const { return false; } ... // all together these properties occupy a single vtable byte virtual bool const propertyA : 1 = false; virtual bool const propertyB : 1 = false; virtual bool const propertyC : 1 = false; virtual bool const propertyD : 1 = false; virtual bool const propertyE : 1 = false; virtual bool const propertyF : 1 = false; }; class C2 : C1 { // override a few properties virtual bool propertyX(void) const { return true; } ... virtual bool const propertyC : 1 = true; }; void foo(C1& myC) { // full cost of a virtual method dispatch if ( myC.propertyX() ) ...; // single fetch, unaltered control flow, better register allocation if ( myC.propertyC ) ...; } |
Posts: 1 / Nickname: mz / Registered: January 28, 2005 6:48 AM
Re: Your C++ Wish List (Editorial)
January 28, 2005 1:09 PM
|
A few times I missed a special destructor that is called on “normal” scope leave but not as part of the stack unwinding on exception. Or perhaps an ability to recognize the stack unwinding run-time. For example if some work should be done on scope leave or say on destruction of a temporary but if no exception occurred only. It should be legal to throw from this “finalizer” code. E.g. Formatting helper when data are prepared and then processed automatically in a single step unless an exception occurred:
Logger(mylog) << “x=” << x; Here Logger::~Logger() logs the formatted message providing additional information like timestamp etc but it should only do so on success but not if an exception occurred. Of course the same can be achieved with just one extra line or an explicit message “terminator” but that’s more verbose and easy to forget. Similar technique might be used for database interfacing (format an SQL query and then execute it if everything is fine), XML tag auto-closure etc. |
Posts: 1 / Nickname: frege / Registered: February 23, 2005 1:35 PM
Re: Your C++ Wish List (Editorial)
February 23, 2005 7:09 PM
|
I would like to solve the problem of ambiguous overriding from 2 base classes:
ie:
which update is C overriding? Can't tell, thus error. How about:
? |
Posts: 1 / Nickname: kolobok / Registered: March 7, 2005 0:28 PM
Re: Your C++ Wish List (Editorial)
March 7, 2005 5:46 PM
|
After coding for many years in both C++ and Java I have in mind some features, which Java lacks and also those, which would be nice to have in C++. Here are two big ones (as I see them):
1) Database connectivity API. I'm actually surprised that this was not pointed out at all. One can say that ODBC is there. But ODBC drivers are often not official on UNIX platforms and in real live there is C++ library for every RDBMS. It would really be nice to have some common standard interface. 2) This one is more in science fiction realm, but let's dream a bit. Reflection. Ability to load code dynamically. This Java feature is so powerful. I can hardly imagine how it can be fully implemented in C++, but at least efficient, programmer-friendly way to access objects in shared libraries as well as defining own object loaders would be first step in this direction. Best regards. |
Posts: 1 / Nickname: nayart3 / Registered: April 4, 2005 4:09 AM
Re: Your C++ Wish List (Editorial)
April 4, 2005 4:19 PM
|
things i would like to see in C++0x:
- C99 variable-length arrays - thread, atomic and aline keywords for variables - naked and deprecated for functions - better inline assembly: guideline rules for standard implementations - a new pointer for garbage collection, with very well defined rules for referencing/dereferencing, etc... - exceptions: add finally; new exceptions to caught things like divide by zero, floating point exceptions, etc... - add rotate left/rigth operators, add support for add/sub/shift with carry - class properties - interfaces - unicode: uchar8, uchar16, uchar32 and wchar for platform default (ex: uchar8 for linux, uchar16 for windows) for a detail description see: http://clientes.netvisao.pt/camop/ please send any comments and suggestions |
Posts: 1 / Nickname: ben04 / Registered: June 13, 2005 3:29 AM
Re: Your C++ Wish List (Editorial)
June 13, 2005 8:31 AM
|
I have 2 propositions.
The first helps to reduce dependencies when the implementations of classes are changed. Consider the following case: header: class A module: void A::foo() Now we spot a bottle neck in A::foo and we rewrite it and therefore introduce a helper function. In the good old C days one would simply have made this one static and the header would not need to be changed. Here although we would need to declare the helper method in the header (assuming it needs access to a) and thus need to recompile all modules using that header for no good reason. Methods do not affect the representation of an instance in memory and therefore technically don't have to be declared in the header if they are not called from outside of the class. I propose that all member functions defined outside of the class declaration and not declared in the class declaration are implicitly declared private, module local and non virtual. This will not break encapsulation as without a public member function defined inside the class declaration you will not be able to invoke member functions declared outside of the class declaration. My second proposition is that the this pointer may be a smart pointer. This would allow for example much better implementations of garbage collectors as one can move the memory of instances around, by encapsulating an additional level of indirection inside the smart pointer, without needing to tell the outside. One problem that although arises is that it is still possible to take the address of a member. This needs further thinking. |
Posts: 2 / Nickname: gcarlton / Registered: June 9, 2005 4:12 PM
Re: Your C++ Wish List (Editorial)
June 9, 2005 8:26 PM
|
Optional argument evaluation.
Sometimes we have debug logging functions that need to be obliterated in final, but even empty inline functions incur the overhead of argument evaluation.
There's no way to avoid the myvector.Length() call in release. This is the one time that I've seen justifiable use of macros in C++ code, simply because there is no other way of doing it. What's needed is an "optional_args" keyword to tell the compiler it can delay or avoid evaluating inline function arguments.
If both priority ints are const, the compiler could just nuke the whole lot, otherwise at least only evaluate the inline arguments until the DoPrint. Note I've avoided var-args since compilers can't easily inline this, which is necessary for the optimisation to occur. |
Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
Re: Your C++ Wish List (Editorial)
June 14, 2005 10:11 PM
|
> Sometimes we have debug logging functions that need to be
> obliterated in final, but even empty inline functions > incur the overhead of argument evaluation. Seriously? Could you provide your profiling output? I can't imagine that any place where you would put a call to the Log::Print() function would be executed enough times to have any impact on a modern CPU. Perhaps if the stubbed inline function was called a few billion times during program execution, it would eat up 1 second. |
Posts: 2 / Nickname: gcarlton / Registered: June 9, 2005 4:12 PM
Re: Your C++ Wish List (Editorial)
June 24, 2005 9:27 PM
|
I've seen the log macro trick used on titles for PS2. Having log functions in the final build is totally pointless. In this case you want the entire thing to be obliterated, including the actual text string itself.
I can also imagine advantages in moving towards asserts using actual functions, with overloaded or templated variants. However thats a moot point until a replacement to __file__, __line__ comes along. Reading through the open-std docs, there are much more interesting things coming to C++, but this little issue has always niggled at me ever since I've seen it. :) |
Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
Re: Your C++ Wish List (Editorial)
June 26, 2005 0:32 AM
|
> I've seen the log macro trick used on titles for PS2.
> Having log functions in the final build is totally > y pointless. In this case you want the entire thing to be > obliterated, including the actual text string itself. Why? I have found that being able to turn on logging on target systems at runtime saves tons of debugging time. I think the value of having that information far outweighs any performance considerations. > I can also imagine advantages in moving towards asserts > using actual functions, with overloaded or templated > variants. However thats a moot point until a replacement > to __file__, __line__ comes along. Or some kind of object standard and support for reflection. I use a nifty Trace() in C# that uses reflection to give the context of the trace. |
Posts: 1 / Nickname: yanko / Registered: November 12, 2004 0:45 AM
Re: Your C++ Wish List (Editorial)
November 12, 2004 6:02 AM
|
I have probably overlooked it but I didn't see anything about implicit forward declarations and doing away with header files completely. I do not pretend to have breadth and insight on this issue, but I have seen other (respectable) people refer to header files as purely compiler assisting concept that is now obsolete given the power of the average machine and level of sophistication compilers achieved. Recursive dependency and source code redundancy are the two major problems stemming from header files that are just on the top of my head now.
But maybe I'm missing the whole point of this new version of C++ - is it supposed to be source-level backwards compatible? |
Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
Re: Your C++ Wish List (Editorial)
November 12, 2004 9:46 AM
|
I agree with you there. Many people have contended that header files provide documentation, but that is a false premise. They often give you more than you want (showing privates, etc.). They can be deceptive, especially when filled with lots of #ifdefs. They are almost always very cluttered. Automatically generated documentation (al la JavaDoc and the like) covers this need much more effectively and aesthetically.
However, from an implementation point of view in C++, it seems like the compiler would have to somehow know how to read libraries. That's kind of what Java and C# compilers do -- they don't have a separate compiler and linker apparently. |
Posts: 1 / Nickname: domdead / Registered: February 15, 2005 8:40 AM
Re: Your C++ Wish List (Editorial)
February 15, 2005 2:06 PM
|
In the same spirit, I'm very afraid of the compile times that all these new features will incur.
Some of the proposed solution, like Bjarne Stroustrup Comparable<T> class just increase the compilation time with no actual code generated. The main application that I'm working on contains about 1500 cpp files (not counting headers) and it takes about 2 hours to compile (Pentium IV, 3GHz, IGB RAM). The dependencies aren't great, but the fact is each file just takes too long to compile. We make extensive of STL and Boost, which greatly increase compilation time for each source file: We could decrease our template usage, but what's the point of using C++ if you can't use the nice templates which make our lifes easier. To give a comparison, a similar sized project in C# compiles in minutes! I do hope the C++ committee will look at proposals to increase compilation times, such as N1736 and others. |
Posts: 1 / Nickname: wor / Registered: June 30, 2005 11:18 PM
Re: Your C++ Wish List (Editorial)
July 6, 2005 6:33 AM
|
> In the same spirit, I'm very afraid of the compile times
> that all these new features will incur. > I also see my compile times skyrocketing. Templates are largly used as workarounds for missing/incomplete features. So on the top of my wishlist is: -- remove Templates and replace them with: 1. subtype polymorphism, higher order functions (for generic programming) 2. make Types first order entities with (compiletime) type operators (for compile time programming/domain specific embedded languages) 3. allow compile time programming with all statically defined objects (explicitly including floats, strings, ...) 4. some access to the lexer (i.e. a _save_ macro replacement), which allows to specially handle user defined types and syntax (for domain specific embedded languages and to finally replace macros) This should reduce boost, blitz, fc++, loki, ... to 30% of their size and make them compile _much_ faster. Apart from that I'd like: --Usable enum's for code like: enum greyScale{white, grey, black}; int color[greyScale]; Range range(greyScale); for (range) { cout << color[range] << " "; // -> white grey black } --Make implicit and default things explicit: e.g: class A { public: implicit A(int a) i(a) {} // implicit by demand default A(A&) {} // generate default constructors only when I say so int operator(){return i;} // explicit by default private: int i; }; -- direct support for multi threading (processes, threads, IPC) |
Posts: 3 / Nickname: zvrba / Registered: August 18, 2005 5:10 PM
Re: Your C++ Wish List (Editorial)
August 22, 2005 7:47 AM
|
I'm surprised that nobody has mentioned type inference. So instead of writing
vector<int>::iterator it = v.begin() make it possible to write: auto it = v.begin(); -or- let it = v.begin(); ('let' shamelessly pulled from Ocaml). typeof() doesn't quite cut it since then I'd have to write typeof(v.begin()) it = v.begin(); This may seem a simple example, but it really pays of with nested templated classes... |
Posts: 4 / Nickname: robotact / Registered: August 27, 2005 2:15 AM
Re: Your C++ Wish List (Editorial)
August 27, 2005 7:09 AM
|
- properties.
- in-place callbacks (Java anonymous classes). - guaranteed size of integer variables: int16, int32, uint16, uint32, so on 8 to 64 bits. Size shouldn't be guaranteed to be the same, but rather at least, so that implementation's speed would be decent. - better enums: strongly typed, in-language way to get value's name (prohibiting to set integer value allows static name table). - information about throw site on throwing and accomulating of call stack (at least function name if not call site of other functions) on processing exception down the call stack. - definition of throwing declaration standard and checked exceptions. - javadoc - @deprecated - #pragma once - virtual (const) static fields for trait types (now it requires private derivation to save that byte in instance). - standard way to set default calling convention as preprocessor #pragma to #include files from libraries with different default convention without need to patch all function declarations in header files of one of libraries. |
Posts: 4 / Nickname: robotact / Registered: August 27, 2005 2:15 AM
Re: Your C++ Wish List (Editorial)
August 27, 2005 7:11 AM
|
> auto it = v.begin();
> > -or- > > let it = v.begin(); I think it would better be v.iterator it=v.begin
|
Posts: 3 / Nickname: zvrba / Registered: August 18, 2005 5:10 PM
Re: Your C++ Wish List (Editorial)
August 27, 2005 7:28 AM
|
>
> I think it would better be > > v.iterator it=v.begin > That doesn't scale well with nested structs and typedefs. If I get you correctly, I would still have to specify the full 'path' to some nested type...? |
Posts: 4 / Nickname: robotact / Registered: August 27, 2005 2:15 AM
Re: Your C++ Wish List (Editorial)
August 29, 2005 10:39 AM
|
Such scalability may as well result is ambiguity of auto type (so that original proposition also wouldn't work).
|
Posts: 2 / Nickname: zadechina / Registered: September 28, 2005 2:50 PM
Re: Your C++ Wish List (Editorial)
September 28, 2005 7:04 PM
|
I want stl associative container(set,map etc) to be more flexible. code like below:
std::set<T> set_obj; std::set<T>::key_compare& kc = set_obj.key_comp(); std::set<T>::iterator iter = set_obj.find(x); *iter = y; kc.change_param(z); I can not change the values directly, and i can not get the key compare functor by refrence.In some special cases, I want to change the element value and the key compare functor synchronously, and I ensure the set's ordering is keeped. I can not do that now. I want the STL change that |
Posts: 3 / Nickname: lpowell / Registered: October 3, 2005 8:06 PM
Re: Your C++ Wish List (Editorial)
October 4, 2005 2:38 AM
|
Introduce an interface keyword that eliminates the hazards of downcasting in a multiple-interface class hierarchy (without requiring RTTI overhead or the use of dynamic_cast). Here's how it could be implemented:
An interface is defined as a struct that cannot contain any non-static data members. All non-static interface methods are virtual. Static data members and static methods are allowed, and constructors and destructors can be optionally defined. Multiple interfaces could then be added to a virtual base, single-inheritance class hierarchy without requiring more than a single vtable pointer in each base and derived class runtime structure. The vtable pointer for each interface would be a component of each of the class vtables rather than a component of each object instance. The advantage is that we could retain the runtime efficiency and reliable downcasting properties of single-inheritance class hierarchies, while taking full advantage of the flexibility of multiple interface inheritance. The only drawback would be the small runtime and code size overheads of the additional level of indirection required to reach interface methods. But since interfaces are intended for module encapsulation rather than efficiency, this would be a minor price to pay. |
Posts: 98 / Nickname: achilleas / Registered: February 3, 2005 2:57 AM
Re: Your C++ Wish List (Editorial)
December 6, 2005 9:24 AM
|
The most important things are:
1) type inference. The keyword 'auto' can be used (already suggested). 2) garbage collection. I am surprised no one has mentioned it. The keyword 'gc' could be used in front of a class. For example 'gc class Foo {}'. Classes derived from garbage-collected classes would automatically be garbage collected. 3) threads. It goes hand-in-hand with gc. 4) lambda functions. It makes a great difference in language usability. 5) no header files. You heard it right: a new way to compile source files and have headers extracted automatically from them. Well, with all the above, C++ will be like D, would it not? :-) |
Posts: 1 / Nickname: gtt / Registered: March 22, 2006 6:12 AM
Lists of types and ability to apply them at compile time.
March 23, 2006 7:42 AM
|
One thing I end up doing a lot in our system here is using the preprocessor to instantiate virtual functions when using the Visitor pattern on a large tree heirarchy, and I'd like to propose an extension to templates that might have applicability elsewhere. In the below example, I'm not particularly suggesting a syntax or any keywords or anything. I'm merely using some things that look like keywords and syntax to get the _concept_ of this across. If there's a better or more succinct way to do it...I'm not a language design expert. ;^)
Let's say I have a heirarchy of tree nodes: class Visitor; class Base { ... }; // This one is abstract. class A : public Base { ... Base& traverse_left(); Base& traverse_right(); ... }; class B : public Base { ... Base& traverse_down(); ... }; class C : public A { ... }; class D : public A { ... }; class E : public B { ... }; class F : public Base { ... }; class G : public F { ... }; class H : public F { ... }; class I : public F { ... }; (Assume that I've declared: void accept(Visitor& v); in every class above.) I'd like to be able to divide this heirarchy into groups of types: type_group SimilarToA = { A, C, D }; type_group SimilarToB = { B, E }; or even better: type_group SimilarToA = { A, has_base_class(A) }; type_group SimilarToB = { A, has_base_class(B) }; type_group SimilarToF = { F, has_base_class(F) }; type_group AllTreeNodes = { has_base_class(Base) }; Then, let's say I was doing some visitors, I would like to be able to do apply these type group at compile time: class Visitor { // "apply<List as Name> { code } " would cause the // compiler to generate code in a fashion similar to // a template, replacing Name in the code between the // braces with each name from the list in succession. // // So the following clause would expand to: // // virtual void Visit(A&) = 0; // virtual void Visit(B&) = 0; // ... // virtual void Visit(H&) = 0; // virtual void Visit(I&) = 0; // apply<AllTreeNodes as T> { virtual void Visit(T&) = 0; } }; Then I can define traversal (and let's assume it's different for the different classes above): class TreeTraversal { // Leaves don't traverse. apply<SimilarToF as T> { virtual void Visit(T& n) { } } // A nodes traverse to the left then the right. apply<SimilarToA as T> { virtual void Visit(T& n) { n.traverse_left().accept(this); n.traverse_right().accept(this); } } // B nodes traverse down. apply<SimilarToB as T> { virtual void Visit(T& n) { n.traverse_down().accept(this); } } }; One might define a design rule using this facility: template<class Base> class MustVisitAllA : public Base { apply<SimilarToA as T> { virtual void Visit(T&) = 0; } } And then when compiling a class that inherits from a concrete instantiation of the rule, you'll be forced to implement all the A visits. One could see that if there were a lot of subclasses of visitor, then this technique could be used quite well to generate methods in them. Right now, to do something similar to the above, I have to use the preprocessor, with all the ugliness and debugging difficulty that this entails. It has been worth it as I probably have a 10:1 ratio of generated methods vs. methods that I have to write (and debug) in our application. I know that the example I give of use of this is specific to my particular design, but I believe that the ability to apply a list of types to the generation of a section of code arbitrarily as above would be a powerful and useful addition to the language. I don't currently know of a way to generate similar memeber functions (or certain other things) without using the preprocessor. Thanks for your time. Let me know if this is of any interest. -- George T. Talbot |
Posts: 3 / Nickname: semantic / Registered: May 21, 2006 3:47 AM
Re: Lists of types and ability to apply them at compile time.
May 21, 2006 9:33 AM
|
I realise I am joining in late in the discussion,
but here goes: 1. default constructor what: The default ctor should be automatically defined (if the user does not provide one) *even if* the user provides other ctors. why: C++ supports value oriented programming (where classes can be used in the same way as builtin types), but having the default constructor behave differently than the copy constructor (in this regard) is confusing (as to why) and unneccessary. If you do not want a value class, inhibit the dflt ctor the same way you would inhibit the copy ctor. 2. hiding vs overloading What: A function "f" (with unique argument types) in a class "Derived" should not hide other f in the base class "Base". It should overload the other f in the base class. Why: Every time I have declared a "f" in a subclass (with other f in "Base", it has been with the intention to overload. Never to hide. Hiding violates LSP. This behaviour in C++ has always surprised me, and I have never felt that it has been right (in 15 years of C++ programming). I know about "using Base::f" but it seems better to have that behaviour as default (that is, overloading). 3. overloading resolution What: When looking for candidate (member) functions, do not consider functions that I can not access (eg. private functions). Only consider functions that are accessible to me at that point. Why: The whole idea of "separating interface from implementation" is about not needing to the implementation. It is not very robust if suddenly I can not compile a piece of code because the implementation needed and declared (in the class) a new function that happens to be the best match *if I could have used it*. I know about the pimpl idiom, but this should have the (in my vew) correct behaviour for the "basic" class usage already. 4. Virtual inheritance This is probably pie in the sky, but this *is* a wish list. What: Make virtual inheritance the deault when there is diamond-like inheritance. (For tree-like inheritance or non-diamond multiple inheritance there should be no change compared to today.) Why: It does not matter that the current default is faster, since it is not generally possible to model multiply ineherited diamond types correctly without virtual inherithance. If there is any need for the faster way of implementing them, let it be indicated by a keyword (instead of the other way around). |
Posts: 3 / Nickname: semantic / Registered: May 21, 2006 3:47 AM
Re: Lists of types and ability to apply them at compile time.
May 21, 2006 11:03 AM
|
I forgot one thing related to point 1. Default constructor
1.5 equality What: For two objects (a and b) of a type T where the copy ctor is defined, the frestanding: bool operator == (const T& a, const T& b) should also be defined, if all subobjects (members/bases) can be compared with '=='. The return value should be the and ('&&') of applying '==' to all subobjects for a and b return a.subobj1 == b.subobj1 && a.subobj2 == b.subobj2 : : Why: The most important property for a value is that it can be compared for equality to another value of the same type. Since equality for aggreagates/composites of well behaved subobjects can be trivially defined (even though it can be cumbersome / error prone to do manually over and over again) the compiler should define operator== if it can and the copy constructor is defined. The easiest way to inhibit this, without explicit language support, is probably to have a member or base that does not have builtin== or operator== defined. One could for example inherit from a noequaality class, that is defined in so that there is no '==' for it. It is somewhat similar to what you need to do if you want to inhibit copy ctor and copy assignment, in the case that you do not have a value class. If you have a value class, the addition of the insistent default ctor and the operator== will really make a difference in how easy it is in the langauge proper to create well behaved value classes from well behaved subobjects. |
Posts: 2 / Nickname: nimnimnim / Registered: November 13, 2006 8:06 AM
"conditional type" definition
November 13, 2006 3:09 PM
|
Using several different external libraries, ie. a rendering engine and a physics engine data types such as Vector, Quaternion etc will be communicated between one library, your gamecode and the other library(ies).
In my case it means cast incompatability as the libraries I'm involved with have no special cooperation. So this leaves me with incompatible Vector3 and Quaternion types which I atm have two of (but what if I had 3?).. This means I need to either make a quite bloated and inefficient takesAllCastsAllClass of these types or write global functions for assignment and casting between these types. (consider this: libAQuat * libBQuat * libCQuat; it would need two temporaries for just this operation.) But if there was a way to define a conditional type like this: conditional_class GenericQuaternion { public: //and maybe this too? more questionable though conditional_type real { float, double }; //has these variables conditions real w, x, y, z; //and possibility to declare function conditions // void normalise(void); }; or in any other syntax defining a conditional type with the conditions that it must have the variables w, x, y and z of type float or double. and the possibility to define conditions of must-have functions (also allowing conditional types and class-types as parameter types) would also be needed for this to be fully usable. That would be sufficient for many perpouses!.. these libraries could in every method possible use this conditional type instead of their own type in function definitions. Like in the Quaternion class of the Ogre3D graphics library. Quaternion operator* (const Quaternion& rkQ) const; (note it's not virtual and mostly they aren't) instead: Quaternion operator* (const GenericQuaternion& rkQ) const; and the compiler would compare conditional_types by their definition when building a project using an external library. Now conditional types should probably not be allowed as return types and wouldn't be needed if all libraries used conditional types for method parameter types but maybe cast operators of conditional types wouldn't be evil either. Then finally I guess the author of each library could use #ifdef USE_CONDITIONAL_TYPES so I hope there's nothing evil about this concept. If it'd be deemed a risky way of coding please consider the performance improvements it could mean for ie. a game using the mentioned libraries which as it stands now makes maybe one or several Quaternion temporaries for each game object every frame when gathering object orientation from the physics engines object and passing it to the rendering engines corresponding scene node (and in between some arithmetic operators are likely to be called on either of these types). |
Posts: 2 / Nickname: nimnimnim / Registered: November 13, 2006 8:06 AM
Re: "conditional type" definition
November 13, 2006 3:16 PM
|
oh and within a conditional_class declaration the conditional methods should be allowed to have conditional types (conditional_class types or conditional_type's) as return types but not within a regular class or struct definition.
|
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 23, 2006 0:28 PM
|
I posted these wishes in another thread (A Brief Look at C++0x), but obviously they belong here!!
1. Variadic templates (as suggested and discussed elsewhere) 2. Anonymous nested objects (here: c.nested) with access to the containing object (here: c of type C). It should be possible to derive their type from a base class (here: 'Base'). I want to suggest different possible syntax for that (it would be enough to have one). struct Base { virtual void foo() {} }; struct C { void foo_C() {} // not possible in c++ nowadays Base { void foo() {foo_C();} // nowadays, c.nested has no access to the members of c. } nested; // not possible in c++ nowadays Base nested {...}; // not possible in c++ nowadays struct {...} nested : Base; // not possible in c++ nowadays struct : Base {...} nested; // possible, but doesn't derive anything struct { void foo() {foo_C();} // not possible - nowadays, c.nested has no access to the members of c. } nested; } c; Base* b = c.nested; b->foo(); To access the members of c, c.nested doesn't need to store a reference. The adress difference of c and c.nested is the same for any object c with type C, so accessing c.foo_C() would technically be no problem. (Nowadays, this can be achieved using the barton-nackmann trick and multi-inheritance, but that's not a nice solution) 3. The same for nested functions - they should as well be able to access other members of the containing class or function. 4. A "This" keyword to identify the type of "*this". template<... ... ...> class A { typedef A<... ... ...> This; // too clumsy, should be done by the compiler!! }; 5. exit loops with a break statement with return value for(...) { ... if(..) break end_of_file(i); else if(..) break end_of_file(i+5); else if(..) break found_error("parsing_error"); ... if(..) break found_error("mature content"); } cout << "normal_break" << endl; label end_of_file(int line_number) { cout << "end of file reached in line "<< line_number << endl; } cout << "normal break or end of file finished" << endl; label found_error(char* message) { cout << "found error " << message << endl; } cout << "normal break or eof or found an error" << endl; These labels are similar to nested functions. The difference is, when they are finished, execution will continue in the line where the label block ends. The same could be achieved with helper functions, but then the code would be scattered in places where it is hard to find. |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 23, 2006 0:49 PM
|
6. class modules. A struct that cannot have instances, pointers, references, and does not even have a size ! It is not a data type, it only serves to compose a bigger class. Like that.
module A { float member_A; virtual void foo_A_v()=0; void foo_A() {foo_C("A");} }; module B { int member_B; virtual void foo_B_v()=0; void foo_B() { foo_C("B"); member_A = member_B; } }; struct C : A, B { void foo_C(char* s) {cout << s;} }; A* a=0; // not possible!! no pointer A* allowed! C* c; // this is allowed. The effect should be similar as copying the code of A and B into the declaration of C. Of course C needs to support the method foo_C(char*), otherwise the compiler will complain. The construction of vtables etc will all happen in C, not in A or B. Therefore, C needs only one vtable pointer. Something like that can be achieved nowadays with the Barton-Nackmann trick (but this doesn't affect the vtable), but I think my version is much better understandable. |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 23, 2006 2:10 PM
|
About modules.
- a module can use members of the child class. - a module itself can be derived from any other module or class. (I don't see any problems with that!) - a module is not a data type. |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 24, 2006 3:40 PM
|
Another way to define modules
// version (i) modular class A { modular void foo_B()=0; void foo_A() {foo_B();} }; struct B0 : A { void foo_B() {cout << "cat";} }; struct B1 : A { void foo_B() {cout << "dog";} }; struct C1 : B1 { void foo_B() {cout << "two dogs";} }; int main() { B0().foo_A(); // writes "cat" B1().foo_A(); // writes "dog" C1().foo_A(); // writes "dog" or "two dogs" ?? (*) } Here the modular keyword is somehow the same as the virtual keyword, but for compile time polymorphism. (*) Obviously, this mechanism needs more thinking!! // version (ii) module A { void foo_B() {Final::foo_B();} // 'Final' keyword to specify the implementing class. }; |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 25, 2006 5:21 AM
|
Class Modules and enhanced member objects - what are they good for?
- class modules can be used instead of the curiously recurring template pattern (crtp). - compared to the crtp, class modules reduce the number of classes to compile. - compared to the crtp, class modules allow multiple inheritance without the typical drawbacks. - member objects of an anonymous class no longer need to store a reference to the enclosing object. Example 1) Efficient way to define properties similar to C#. // could be done with curiously recurring template patterns instead of class modules. template<typename value_type> module M_T { Final& operator += (value_type value) { Final::set(value); } ... // the entire interface }; struct C { int update_count; M_T<float> weight { // anonymous class derived from the module! float val; void set(float value) { val=value; ++update_count; // easy access to enclosing class } float get() {return val;} }; }; int main() { C c; c.weight = 9.2f; c.weight += 3f; } Example 2) Workaround for the lack of virtual function templates template<typename T> module M_Base_T { virtual void foo_v(T)=0; // overloading instead of template argument }; struct Base : M_T<C0>, M_T<C1>, M_T<C2> { // only one vtable pointer needed !! template<typename T> void foo() {foo_v(T);} }; template<typename T> module M_Imp_T : public virtual Base { virtual void foo_v(T) { Final::foo_imp<T>(); } }; struct M_Imp : M_Imp<C0>, M_Imp<C1>, M_Imp<C2> { }; // user code struct MyClass : M_Imp { template<typename T> void foo_imp() { ... // implementation } }; It's maybe too late for these suggestions to get into C++0x. However, I'm really missing at least the enhanced member objects, which would be very easy to implement imo! |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 27, 2006 4:39 AM
|
Example 3) A little state machine (with performance benefits compared to if-else, if there is a higher number of states)
struct SimpleStateMachine { SimpleStateMachine() {current_state=state_A;} void step() {current_state->step();} private: struct State { virtual void step()=0; } * current_state; State state_A { // derived from struct State virtual void step() {current_state=state_B;} }; State state_B { // derived from struct State virtual void step_v() {current_state=state_A;} } }; |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
November 27, 2006 4:40 AM
|
ehm, in better markup
Example 3) A little state machine (with performance benefits compared to if-else, if there is a higher number of states) struct SimpleStateMachine { SimpleStateMachine() {current_state=state_A;} void step() {current_state->step();} private: struct State { virtual void step()=0; } * current_state; State state_A { // derived from struct State virtual void step() {current_state=state_B;} }; State state_B { // derived from struct State virtual void step_v() {current_state=state_A;} } }; |
Posts: 1 / Nickname: gnu / Registered: April 8, 2007 4:43 AM
Re: Your C++ Wish List (Editorial)
April 8, 2007 9:54 AM
|
C++ has no standard for adding assembly
lines for the source code(Compilers act on there own ways). why don't we make a standard to this via C++0x ? |
Posts: 7 / Nickname: rgamarra79 / Registered: September 26, 2008 3:00 AM
Re: Your C++ Wish List (Editorial)
October 10, 2008 7:36 AM
|
Hi lemon head. I'm interested in nested classes being able to access "this". In one of your posts you told that the nested object doesn't need to store a reference, that "this can be achieved using the barton-nackmann trick and multi-inheritance, but that's not a nice solution".
Can you give a brief example of the involved technique? Thanks a lot. Rodolfo. |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
October 10, 2008 10:46 AM
|
[quote]Hi lemon head. I'm interested in nested classes being able to access "this". In one of your posts you told that the nested object doesn't need to store a reference, that "this can be achieved using the barton-nackmann trick and multi-inheritance, but that's not a nice solution".
Can you give a brief example of the involved technique?[/quote] I am trying to remember :) I had already given up on the idea, after seeing that noone is interested in it (including Mr. Bj. Str. in persona - but maybe this is because he gets tons of messages a day) I hope my C++ is not too rusty in the meantime. You can use this trick, but then it will no longer be a "nested object", but a "parent class". I'm not even sure anymore if Barton-Nackman is the correct name for the mechanic. Often it is called "curiously recurring template pattern" http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern // nested object class Nested { virtual void foo_nested() {} } class Outside { void foo_outside() {..} Nested nested { void foo_nested() { // finds the method in class Outside foo_outside(); } }; // nested object } Outside().nested.foo_nested(); // CRTP solution template<class T> class NestedT { void foo_nested() { static_cast<T*>(this)->foo_outside(); } } class Outside extends NestedT<Outside> { void foo_outside(); } Outside().foo_nested(); |
Posts: 7 / Nickname: rgamarra79 / Registered: September 26, 2008 3:00 AM
Re: Your C++ Wish List (Editorial)
October 10, 2008 11:21 AM
|
Thanks a lot for your reply lemon head, and nice trick.
I saw also some pages discussing the difference between CRTP and barton-nackmann's trick. I'll analyze it depth but it seems that it isn't what I was looking for: I'd prefer to avoid the inversion "nested object" to "parent class". Despite, I thought of using it with several nested classes/structs, so I'd say that that rules out this approach. Maybe storing a pointer to 'this' is the only safe way to do this; which is, put it simply, what Java does. I'm also considering some way of calculating outer's 'this' from within the nested class. In principle having nested's 'this' and the field offset it could be achieved. Something like (Within nested) reinterpret_cast<OuterType*>(this - nested field offset within outer); But I believe that it could be, so to say, very dangerous. In some webpages a way to calculate the offset is proposed, but it involves dereferencing 0. At last, see that you used extends in the C++ example (Outside class definition). Thanks again, cheers. Rodolfo |
Posts: 11 / Nickname: lemonhead / Registered: November 23, 2006 0:53 AM
Re: Your C++ Wish List (Editorial)
October 10, 2008 11:35 AM
|
You are right, it is absolutely possible via offset calculations. Usually we can assume that the compiler will use the same offset for every object. But still it's stinky...
My proposal was to provide a native syntax for this offset trick, and let the compiler guarantee that it works correctly. About the Java way: In Java you HAVE to store the reference to 'this', because the nested object is not statically nested in the enclosing object, but dynamically. In C++ we have the nested and enclosing object in the same block of memory. The static nesting gives a memory benefit, and also reduces indirection. This is usually not worth the trouble, but it can make a lot of sense when programming large data structures with very small atomic objects. |
Posts: 7 / Nickname: rgamarra79 / Registered: September 26, 2008 3:00 AM
Re: Your C++ Wish List (Editorial)
October 13, 2008 0:07 PM
|
Hi lemon head,
Yes, due to Java's heap-allocated objects the pointer is needed. I sketched two template classes, exploring the two approaches.
To use the last one, is useful the macro offsetof (defined in <cstddef>). It's interesting to note that, it seems, there're news about that macro in ISO/IEC C++ standard. For instance, take a look at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2172.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2369.pdf It seems that they're broadening the kind of types the macro may be applied. The inner cast (to a "sizeof == 1" type) was used to avoid scaling during the arithmetic. Thanks. Rodolfo. |
Posts: 1 / Nickname: zar / Registered: December 31, 2008 11:50 PM
Re: Your C++ Wish List (Editorial)
January 1, 2009 6:55 AM
|
In my opinion two most important additions to C++ would be:
1) Compile time meta information (Something like Daveed Vandevoorde's metacode). 2) Standard modules - C++ version of Java class files or .net assemblies. These two features could revolutionize C++ once again. Compile time meta information. Although template metaprogramming is a very cool and interesting way of getting some things done, It looks too complicated and has certain limitations that are direct consequence of the lack of the type information during the compilation. Some metadata can be obtained using quite indirect and unnatural tricks, but anyway, that approach is too limited. Even if it's too difficult to implement all Daveed's ideas, at least some way to iterate over class/template's members/member functions and their types would be very useful. Something resembling .net attributes but available during the compile time instead of (or in addition to - optionally) runtime - would be awesome. This would enable a whole gamut of new powerful techniques. All this additions revolving around the metadata issue would greatly reduce the need for code generation tools for C++ resulting in more portable elegant and generic solutions. Optionally, making this rich metadata (extended RTTI) available during the runtime would be also handy, but I'm not a big fan of that idea because it might encourage structurally simple but inefficient Java/C# style solutions. 2) Standard modules. This would make possible to share C++ binaries across different OSes and platforms as long as the CPU instruction set is the same. Platform specific code could be isolated in platform specific binaries with the same C++ interfaces. Ability to include those modules would also be nice. This is already implemented in MSVC: #import "some.dll" Just make it something portable and standard. 3) I agree that access to host class members/functions from the nested class could be useful in some cases and not too difficult to implement. I believe implementation complexity would be similar in a way to multiple (virtual) inheritance. From the conceptual point of view it's no uglier than MI itself or friends for example. multiple levels could be handled with either scope resolution operator, or additional keyword (host?): 1) OuterHostClassName::this->someFunc(); or 2) host.host.someFunc(); whichever feels more consistent with C++ syntax. |