- Function declaration default to another param's value - 8 Updates
- "Why I don't spend time with Modern C++ anymore" by Henrique Bucher - 2 Updates
- About C++ style (functions) - 1 Update
- OT: Association for Orthodox Jewish Scientists - 1 Update
- "C++17 is taking shape" - 2 Updates
- "C++17 is taking shape" - 2 Updates
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 07 05:45AM -0700 On Monday, June 6, 2016 at 9:42:06 AM UTC-4, Alf P. Steinbach wrote: > Yes. > Cheers, and sorry that this can't be much help!, > - Alf It's all good. :-) Personally, I think it's a missing feature, and I'm surprised someone of influence in the C++ standards group hasn't already wanted this ability by now. But, as Bo Persson points out, an easy work-around. That's probably why. I think this is also a missing feature: // In header int myfunc(int a, int b = local_b); // In body int myfunc(int a, int b) { return(a + b); } // Where referenced in source code int elsewhere(void) { int local_b = 5; return(myfunc(1)); } I think the ability should exist for parameter defaults to be able to reference things that are in scope locally or globally. Best regards, Rick C. Hodign |
David Brown <david.brown@hesbynett.no>: Jun 07 03:55PM +0200 On 07/06/16 14:45, Rick C. Hodgin wrote: >>> } >>> Is it allowed? >> Nope. What would be the use-cases of such a default parameter? I could think of a few occasions, but none that would be common enough to make it worth adding to the standard. And rather having the default of "val2" being simply the same as "val1", I think there would be more useful cases for the default of "val2" being an expression in "val1". But that would quickly get difficult to specify well - and I think Bo Persson's neat workaround makes complicated defaults unnecessary. Rather than writing: void sendString(const char* p, int len = strlen(p)); you just write: void sendString(const char* p, int len); inline void sendString(const char* p) { sendString(p, strlen(p); } >> int x; >> void foo( int t = x ) {} //! Nyet. >> }; That could be neat. But again, it can be handled by the easy workaround. On the other hand, given that there /is/ an easy workaround, then it should not be too difficult to implement the syntax you want. > } > I think the ability should exist for parameter defaults to be able to > reference things that are in scope locally or globally. This would make the header file depend on variables declared in the source file that uses the header - that's going to open a /huge/ can of worms. In C++, you can currently write: #include <functional> using std::bind; using namespace std::placeholders; int elsewhere(void) { int local_b = 5; auto org_myfunc = myfunc; auto myfunc = bind(org_myfunc, _1, local_b); return myfunc(1); } or, using lambdas, int elsewhere(void) { int local_b = 5; auto org_myfunc = myfunc; auto myfunc = [local_b, org_myfunc](int a) { return org_myfunc(a, local_b); }; return myfunc(1); } or, using classes, class Fmyfunc { private : int def_b; public : Fmyfunc(int default_b = 0) : def_b(default_b) {}; int operator()(int a, int b) { return myfunc(a, b); }; int operator()(int a) { return (*this)(a, def_b); }; void setDefault(int default_b = 0) { def_b = default_b; }; }; int elsewhere(void) { int local_b = 5; auto myfunc = Fmyfunc(local_b); return myfunc(1); } You can also use templates in creative ways here. (In each of these cases, gcc has no problem generating optimal code, so there is no run-time overhead.) In other words, you can make your own local version of "myfunc" which has local modifications (such as a different default). This puts the control of the local modifications where it should be, where it is used - and leaves the definition and implementation of myfunc unaware of the local modifications. The challenge for your language is to come up with a neater syntax for doing this! An obvious improvement would be to allow: auto myfunc = bind(myfunc, _1, local_b); instead of auto org_myfunc = myfunc; auto myfunc = bind(org_myfunc, _1, local_b); A key point here is to allow functions to be manipulated directly, or nearly directly - if functions are first-class objects, all sorts of tricks are possible. |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 08 12:35AM +0300 On 7.06.2016 15:45, Rick C. Hodgin wrote: > } > I think the ability should exist for parameter defaults to be able to > reference things that are in scope locally or globally. This would be too magic/transparent. In source code, a local variable local_b is created, but one could not check by textual search if and where it is used. That would be a major no-no. (Been there, done that. Believe me, it's not a good idea). Cheers Paavo |
BartC <bc@freeuk.com>: Jun 07 10:50PM +0100 On 07/06/2016 13:45, Rick C. Hodgin wrote: > int local_b = 5; > return(myfunc(1)); > } (1) When a default expression is used for a parameter, should it look: (a) around the header declaration to resolve the names encountered in the expression? (b) around the definition of the function (which will usually not be visible at the call-site)? (c) at the call-site? (2) In your above example, presumably you want formal parameter 'b' in myfunc() to be set to local_b from the call-site. But what happens when myfunc() is called from anywhere else? (I can't anyway see how it can work when writing a library function, and you use a default name that exists in a caller's module; how do you know what's in the caller's code?) (3) (I understood that in C at least, the names chosen for parameters in declarations were arbitrary, so this would be a problem for the example in your OP (as changing parameter names could change the behaviour if it means a different name coming into scope for the default expression).) -- Bartc |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 07 02:51PM -0700 Paavo Helde wrote: > (Been there, done that. Believe me, it's not a good idea). I'm not prepared to make that decision for all developers everywhere at all times and in all cases. https://groups.google.com/forum/!topic/caliveprogramminglanguage/DY-RAJ7zaM8 |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 07 02:57PM -0700 Oops! Mobile screen jumped and I hit "Post"! Paavo Helde wrote: > (Been there, done that. Believe me, it's not a good idea). I'm not prepared to make that decision for all developers everywhere at all times and in all cases. https://groups.google.com/forum/?nomobile=true#!topic/caliveprogramminglanguage/DY-RAJ7zaM8 I can think of times I could use it. Best regards, Rick C. Hodgin |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 08 01:06AM +0300 On 8.06.2016 0:51, Rick C. Hodgin wrote: >> (Been there, done that. Believe me, it's not a good idea). > I'm not prepared to make that decision for all developers everywhere > at all times and in all cases. Well, I am, at least for C++ developers. Making use of such a feature would effectively turn the language into a write-only language, similar to Perl or advanced regex. This might be OK for some quick prototyping languages, but this is not the niche of C++. Cheers Paavo |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 07 03:08PM -0700 Bart Mancuso spoke: > " 'Central Intelligence Agency' ... now there's a contradiction in terms." Bartc wrote: > [paraphrased] "Where should it look?" (1) Other parameters. (2) Scoped variables. (3) Local variables. (4) Global variables. (5) Solar variables. (6) Galactic variables. (7) Universal variables. (8) If on a Windows machine, the registry. (9) If on a computer with a recycle bin, the recycle bin. (10) Popup a console and ask, and don't take "no" for an answer (unless the variable name is "no," of course). (11) If they pressed Ctrl+C, use Google. :-D Best regards, Rick C. Hodgin |
Juha Nieminen <nospam@thanks.invalid>: Jun 07 06:05AM > larger projects and it affects them. It doesn't take long. > It's not my problem that the biggest program you ever wrote was "Hello > World". I think you have some kind of reading comprehension problem. --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
Jerry Stuckle <jstucklex@attglobal.net>: Jun 07 11:13AM -0400 On 6/7/2016 2:05 AM, Juha Nieminen wrote: >> World". > I think you have some kind of reading comprehension problem. > --- news://freenews.netfront.net/ - complaints: news@netfront.net --- Not at all. But you seem to. Let me try again. Just because you don't have a problem with compile time doesn't mean others don't. And yes, there are many programmers who work on larger projects and it affects them. Of course, when the biggest program you write is "Hello, World!", compile time isn't a problem. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ================== |
Juha Nieminen <nospam@thanks.invalid>: Jun 07 06:18AM > void ThisIsFoo(); > but then noticing that many used lower letter I recently used some years: > void thisIsFoo(); Many people like to distinguish between functions and types, and the most common way of doing that is to use that first letter. After all, using that naming convention, foo() and Foo() mean rather different things, which becomes apparent from the name even without knowing anything about that function/class. It may be a small thing, but it can help. --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
woodbrian77@gmail.com: Jun 06 06:57PM -0700 On Monday, June 6, 2016 at 4:24:01 AM UTC-5, J. Clarke wrote: > > http://webEbenezer.net > So our duty is to keep increasing the population until we run out of > food and everybody dies? "Now without faith it is impossible to please Him, for the one who approaches G-d must believe that He exists and that He rewards those who seek Him." Hebrews 11:6 Recall how Yeshua (aka Jesus) multiplied the loaves and fishes. Some people had to give up their provisions/food in order for Him to do that. They had journeyed out in the country a ways to find Him. > How many kids do you have and by how many women? I think J.S. Bach had over 20 children between two wives. He was blessed in many ways. "Bach: Music in the Castle of Heaven" For me it's software in the castle of heaven. Brian Ebenezer Enterprises http://webEbenezer.net |
Real Troll <real.troll@trolls.com>: Jun 07 01:25AM +0100 On 06/06/2016 23:49, Stefan Ram wrote: > assume that after > auto x{ 1.7 }; > »x« has the type »double«, not »initializer_list<double>«. What is website? Can anybody download the example programs? |
Real Troll <real.troll@trolls.com>: Jun 07 01:49AM +0100 On 07/06/2016 01:36, Stefan Ram wrote: > http://www.purl.org/stefan_ram/pub/c++_blockkonstanten_de > . (Less than 5 % of all visitors get a "403" status, > these might try to visit with a Google referrer.) Thank you Stefan and good luck to Germany in Euro 2016. |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 06 10:49PM >I am getting excited here. Do you know what are the main changes and >which tool has already started implementing these changes. Is VS2015 >ready for it? For me, the main change is obvious. It is what I am already using in my teaching for months. Many example programs from my C++ course won't compile with C++14 anymore, because I assume that after auto x{ 1.7 }; »x« has the type »double«, not »initializer_list<double>«. |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 07 12:36AM >What is website? Can anybody download the example programs? I am publishing my course notes in the World-Wide Web, but they are written in the German language and the course addresses beginners. I am not satisfied yet with the state of my notes, more work needs to be done, they are more a preliminary draft. But, FWIW, the URI of the course notes is http://www.purl.org/stefan_ram/pub/c++-kurs and an example page with example programs including C++17 programs is http://www.purl.org/stefan_ram/pub/c++_blockkonstanten_de . (Less than 5 % of all visitors get a "403" status, these might try to visit with a Google referrer.) |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment