473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 suggested new features for C++

1)

Support the idiom:

p - static_cast<C:: *M>(p)

C is a class.
M is a data member of C (not a type).
The value of p must implicitly convert to the type of M.
If the value of p (after conversion) is the address of
the member M of some instance of C, the result
of the "expression " has type C * and is the address of
the instance of C. Otherwise, the result is undefined.

This idiom could be supported directly, or by
allowing C::*M as a new sort of pointer, that
would only have default and copy constructors,
assignment. Otherwise only usable in this
weird new overload of -.

2)

Allow

class X.Y ... ;

to indicate that class Y can only be used as the
type of data members of class X. If Y is member
of class X, X can be omitted:

class .Y ... ;
Jul 10 '08
19 1184
James Kanze wrote:
Well, my first wish would be that compilers would actually
implement the features we've got (e.g. like export).
Not to talk about the features of the upcoming standard. I'm really
drooling over rvalue references...
Jul 11 '08 #11
W Karas <wk****@yahoo.c omkirjutas:
On Jul 10, 1:21 pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
>W Karas wrote:
1)
[..]
2)
[..]

Can you perhaps explain what problems those solve (that can't be solved
now by any other means)? Thanks!

1)

The rational is the same as for having the
capability to get the address of a derived
class instance from the address of the
base class instance within the derived
class instance.
This can be done now by making the classes polymorphic and using the
dynamic_cast<op erator.

If this approach for inherited classes is OK, you can easily use the same
mechanism for a data member - just put this data member into a separate
class and (multiple) derive from that. The drawbacks are possible
performance loss (possibly not important in most cases) and the fact that
the inheritance cannot be private, thus making the implementation details
visible outside of the class. If I wanted to make a standards change
proposal I would instead vote for refining dynamic_cast<ru les so that it
would work for such private inheritance in certain contexts (like inside
member functions of the classes involved (the one privatly inheriting and
the one inherited from)). But of course it's too late now to change
anything here.

Regards
Paavo
Jul 13 '08 #12
James Kanze wrote:
On Jul 11, 4:21 pm, Juha Nieminen <nos...@thanks. invalidwrote:
> I apologize for shamelessly put this here, but it seemed to be a
proper place... :)
> I have compiled my own C++ wishlist, if anyone is interested:
>http://warp.povusers.org/cpluspluswishlist.html

Well, my first wish would be that compilers would actually
implement the features we've got (e.g. like export).
I think I gave up hoping for export in compilers not based on the EDG
front-end when H. Sutter presented his paper "Why We Can't Afford Export"

<http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1426.pdf>

about five years ago. The minutes of the following meeting

<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1459.html>

show that pretty much nobody in the committee took it into much
consideration (see the straw poll results) but it seemed to generate
quite an outcry in the world outside. It was IMHO a "Why we
--Microsoft-- don't want to tackle export" which turned into "Why
top-most experts like Herb Sutter say that if I think I'm capable to
implement export than I haven't understood it" for every other
implementor.

And, alas, note that *even* most of the EDG-based compilers come with
export disabled.

--
Gennaro Prota | <https://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
Jul 14 '08 #13
Gennaro Prota wrote:
I think I gave up hoping for export in compilers not based on the EDG
front-end when H. Sutter presented his paper "Why We Can't Afford Export"
If I'm not completely mistaken, the latest gcc does support export
templates.
Jul 14 '08 #14
On Mon, 14 Jul 2008 19:12:41 +0000, Juha Nieminen wrote:
Gennaro Prota wrote:
>I think I gave up hoping for export in compilers not based on the EDG
front-end when H. Sutter presented his paper "Why We Can't Afford
Export"

If I'm not completely mistaken, the latest gcc does support export
templates.
I think you may be mistaken... where did you see that? My 4.3.1 (current
stable) doesn't and the documentation under "Current development"
(http://gcc.gnu.org/onlinedocs/) still says "GCC implements the majority
of C++98 (export is a notable exception)...".

--
Lionel B
Jul 15 '08 #15
Lionel B wrote:
I think you may be mistaken... where did you see that? My 4.3.1 (current
stable) doesn't and the documentation under "Current development"
(http://gcc.gnu.org/onlinedocs/) still says "GCC implements the majority
of C++98 (export is a notable exception)...".
http://gcc.gnu.org/gcc-4.3/cxx0x_status.html

Maybe I got confused with "extern template" (which I really don't know
what it means, if it's something different than an export template).
Jul 15 '08 #16
Gennaro Prota wrote:
I think I gave up hoping for export in compilers not based on the EDG
front-end when H. Sutter presented his paper "Why We Can't Afford Export"

<http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1426.pdf>
IMO that paper is a bit misleading in one point: It seems to make it
sound like the only (and imaginary) advantage of export templates is
that you can reorganize your code better (that is, you don't have to put
everything in header files), and that's about it. The section 2.4 is
even titled "provides little or no value".

Unless I have understood export templates incorrectly (and please
correct me if I'm wrong, I really want to get this straight), export
templates allow for better modularity (which is one of the most, if not
the single most important feature of object-oriented programming).

Without export templates (which is the current situation with
basically all compilers) it's impossible to have templated classes and
functions which have private code inside their own compilation unit
(that is, inside a nameless namespace). In other words, non-export
templates can *not* use their own private nameless namespaces because
they don't have their own private compilation unit.

Unless I'm completely mistaken (please correct me if I am), export
templates can use data and code inside a nameless namespace inside the
compilation unit where those templates are implemented. This allows for
greater modularity and data hiding. The larger the amount of data and
code inside this nameless namespace, the more important it would be for
it to be inside that namespace. (For example trying to put hundreds or
even thousands of lines of non-templated code, or unrelated templates,
inside the private section of a template class as static data and static
functions can quickly make the header file a huge mess. With template
functions you can't even do that at all.)
Jul 15 '08 #17
Juha Nieminen wrote:
Gennaro Prota wrote:
>I think I gave up hoping for export in compilers not based on the EDG
front-end when H. Sutter presented his paper "Why We Can't Afford Export"

<http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1426.pdf>

IMO that paper is a bit misleading in one point: It seems to make it
sound like the only (and imaginary) advantage of export templates is
that you can reorganize your code better (that is, you don't have to put
everything in header files), and that's about it. The section 2.4 is
even titled "provides little or no value".
A comment that I'd actually apply to the paper :-) Frankly it is
probably the worst of all H. Sutter's writings, from a technical point
of view.
Unless I have understood export templates incorrectly (and please
correct me if I'm wrong, I really want to get this straight), export
templates allow for better modularity (which is one of the most, if not
the single most important feature of object-oriented programming).

Without export templates (which is the current situation with
basically all compilers) it's impossible to have templated classes and
functions which have private code inside their own compilation unit
(that is, inside a nameless namespace). In other words, non-export
templates can *not* use their own private nameless namespaces because
they don't have their own private compilation unit.
[further elaboration snipped...]

I believe you got it very right. I'm not saying that the world can't
leave without export but certainly the paper presents an unbalanced
view of the matter. Frankly, even the 4.5 person-years... is it such a
show-stopper for a compiler vendor? At EDG, of course, they were just
three at the time, so the issue was a tad different for them :-)

--
Gennaro Prota | <https://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
Jul 15 '08 #18
Juha Nieminen wrote:
I apologize for shamelessly put this here, but it seemed to be a
proper place... :)

I have compiled my own C++ wishlist, if anyone is interested:

http://warp.povusers.org/cpluspluswishlist.html
One feature I'd love to see is support for keyword arguments when
calling a function. When a function looks like:

void MyObject::Funct ion(int x, int y, int z = 0 int z2 = 5 int z3 = 10)

it would be nice to be able to do something like:

a.Function(x, y, z3 <-- 20)

to specify a value for z3 without changing/specifying defaults for z and z2.

Brian Vanderburg II
Jul 16 '08 #19
Allen wrote:
One feature I'd love to see is support for keyword arguments when
calling a function. When a function looks like:

void MyObject::Funct ion(int x, int y, int z = 0 int z2 = 5 int z3 = 10)

it would be nice to be able to do something like:

a.Function(x, y, z3 <-- 20)

to specify a value for z3 without changing/specifying defaults for z and
z2.
Some programmers argue that default function parameter values are
actually bad design, at least if there are many of them. Personally I
can't decide one way or the other (but I do find them handy in many cases).
Jul 18 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
1967
by: P.C. | last post by:
Hi My son like many youngsters been around computers, fast online games, he acturly for main part learned to read and write ,beside his second language english , and may I say he is quite good at it age 15 , but as some of you know, 3D games also offer edditors and script options , or rather programming choppers and dust clouds in scenes. Now beside my bad english, my problem is, that I like him to learn decent programming ------- sure...
2
1695
by: Pavils Jurjans | last post by:
Hello, I have a fairly complex project with server-side written in C# (.NET), and client-side heavily relying on the presence on JavaScript-compatible scripting engine. One of the features thie project utilizes is "virtual POST", ie, client side submits the data to the server side, using Microsoft.XMLHTTP ActiveX Object (in MSIE), or XMLHttpRequest class in Mozilla, and when the server returns reply, processes it in client side to run...
18
1777
by: Michael B Allen | last post by:
Is it considered a bad idea to use a C99 only feature? It has been almost 6 years right? Specifically I'm interested in variadic macros. All of my code is C89 (or less) except for my debugging macros. Thanks, Mike
8
1941
by: Servé Lau | last post by:
I've read the new features that are coming to the next VC and they all sound fine. But I was missing new standard C++ features, will the features like export still not be implemented? What about C features like designated initializers? struct X { int x; int y; }; X x = { .x = 2, .y = 3 };
6
2446
by: aron t | last post by:
Hi, I am good php programmer and want to learn asp.net. Can someone tell me what are the best and the worst features of ASP.NET? thanks
4
1120
by: Sandy | last post by:
Hello - I have developed the world's ugliest website -- functions well, but it leaves a lot to be desired aesthetically. What are the recommended web graphics programs to integrate with Visual Studio projects? I don't want to just go out and buy something without knowing it works well with VS. Also, how would you integrate it? Just copy and paste stuff?
7
3174
by: Fister | last post by:
I'm reading Professional C# (Wrox) and stumbled across: "Some features are supported by.NET but not by C#, and you might be surprised to learn that some features of the C# language are not supported by .NET (for example, some instances of operator overloading)!" How can some features be supported by C# and not .NET? Are there other features than operator overloading and could someone please supply an example? / Fister
5
2587
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization algorithm to solve a certain messy problem, and many different things. For that I often use several general modules that I have written, like implementation of certain data structures, and small general "utility" functions/classes, plus of course...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.