- "owner-concept" or "GSL" ...? - 1 Update
- C++ 2017 -- win, lose and draw - 3 Updates
- Is this definition of an array legal? - 9 Updates
- Why study the Bible? What can we learn? - 6 Updates
- Fun with macros :) - 1 Update
- Could this container I made have any use? - 4 Updates
- The first non-duplicated letter in a string - 1 Update
Bonita Montero <Bonita.Montero@gmail.com>: Feb 02 06:49PM +0100 Can anyone explain me what the "owner-concept" or "GSL" of C++17 is? -- http://facebook.com/bonita.montero/ |
Daniel <danielaparker@gmail.com>: Feb 01 07:01PM -0800 > The advent of the C++ Middleware Writer is further evidence > of G-d's sovereignty. It's nice to see that Brian has a sense of self deprecating humour! Daniel |
"Öö Tiib" <ootiib@hot.ee>: Feb 02 05:50AM -0800 On Thursday, 2 February 2017 05:01:36 UTC+2, Daniel wrote: > > The advent of the C++ Middleware Writer is further evidence > > of G-d's sovereignty. > It's nice to see that Brian has a sense of self deprecating humour! Serious fundamentalistic positions are typically indistinguishable from self-irony and parody. |
woodbrian77@gmail.com: Feb 02 09:41AM -0800 On Wednesday, February 1, 2017 at 9:01:36 PM UTC-6, Daniel wrote: > > The advent of the C++ Middleware Writer is further evidence > > of G-d's sovereignty. > It's nice to see that Brian has a sense of self deprecating humour! You may wish to cast me as a villain because you also consider Moses and Aaron to be villains. By faith they stood up to Pharoah, and G-d freed millions of people who had been slaves to a powerful regime. I'm with those who realize they are prone to slavery and need G-d as much as the ancient Israelites did. Brian Ebenezer Enterprises - "My brothers, G-d called you to be free. But do not use your freedom as an excuse for letting your physical desires control you, but through love seek the best for one another." Galatians 5:13 |
Paul <pepstein5@gmail.com>: Feb 01 06:09PM -0800 Is the below code legal? On the one hand, the array length seems constant as required. On the other hand, I read that a non-reference const as a function parameter is the same type as a non-const. For example you can't overload void f(const int); with void f(int); Thanks for letting me know. Paul // CODE BELOW void makeArray(const int K) { int a[K]; } |
karolak kolo <karolakkolo123@gmail.com>: Feb 01 06:18PM -0800 Unfortunately it isn't possible by declaring an array this way. Even though the argument is constant, the argument used when actually calling the function may not be constant anymore. Also, the array will stop existing as soon as the function ends because it is local, not global. You can do it an other way though, using operator new, and defining the arrat globally. int* globalArray; void makeArray(int n) { delete[] globalArray; globalArray = new int [n]; } You have to be careful with this though. You probably want to read more about the operator new[], delete[] and pointers. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 02 03:29AM +0100 On 02.02.2017 03:09, Paul wrote: > { > int a[K]; > } The `K` here is not known at compile time (and context isn't considered: it doesn't matter if there is only one one call of `makeArray` and that call has a literal value as argument). And so in standard C++ this is not valid code. In standard C++ the size of an array variable must be compile time constant. However, in C99 the above is valid. There it's a variable length array, called a VLA. For variadic arrays `sizeof` is evaluated at run-time. The g++ compiler supports C99 VLAs as a language extension. To avoid having non-portable code like that silently accepted you can use the option `-pedantic`, which produces warnings about such constructs, but still let the compiler produce an executable. I prefer to have these warnings treated as errors, via `-pedantic-errors`. In Windows' command interpreter `cmd.exe`, where `doskey` is used to define an alias with relevant options: [example] [C:\my\temp] > doskey g++=g++ -std=c++14 -Wall -Wextra -fexec-charset=cp1252 $* [C:\my\temp] > type foo.cpp void makeArray(const int K) { int a[K]; } auto main() -> int {} [C:\my\temp] > g++ foo.cpp foo.cpp: In function 'void makeArray(int)': foo.cpp:3:9: warning: unused variable 'a' [-Wunused-variable] int a[K]; ^ [C:\my\temp] > g++ foo.cpp -pedantic foo.cpp: In function 'void makeArray(int)': foo.cpp:3:12: warning: ISO C++ forbids variable length array 'a' [-Wvla] int a[K]; ^ foo.cpp:3:9: warning: unused variable 'a' [-Wunused-variable] int a[K]; ^ [C:\my\temp] > g++ foo.cpp -pedantic-errors foo.cpp: In function 'void makeArray(int)': foo.cpp:3:12: error: ISO C++ forbids variable length array 'a' [-Wvla] int a[K]; ^ foo.cpp:3:9: warning: unused variable 'a' [-Wunused-variable] int a[K]; ^ [C:\my\temp] > _ [/example] Cheers & hth., - Alf |
Paavo Helde <myfirstname@osa.pri.ee>: Feb 02 08:41AM +0200 On 2.02.2017 4:18, karolak kolo wrote: > delete[] globalArray; > globalArray = new int [n]; > } Please do not advocate mutable globals, uninitialized data or lack of RAII here! Somebody reading this group might get an idea that this kind of code is actually acceptable. > You have to be careful with this though. You probably want to read more about the operator new[], delete[] and pointers. Why? What's wrong with std::vector? Everything you need to know about new[] is that whenever you feel compelled to use it then most probably you are doing something wrong. Cheers, Paavo |
scott@slp53.sl.home (Scott Lurndal): Feb 02 01:31PM >Please do not advocate mutable globals, uninitialized data or lack of >RAII here! Somebody reading this group might get an idea that this kind >of code is actually acceptable. It is actually aceeptable. |
Paavo Helde <myfirstname@osa.pri.ee>: Feb 02 04:54PM +0200 On 2.02.2017 15:31, Scott Lurndal wrote: >> RAII here! Somebody reading this group might get an idea that this kind >> of code is actually acceptable. > It is actually aceeptable. In a very special situation and extra careful programmers - maybe. But do you imagine how many bugs the average noob will create when writing this kind of code? Cheers Paavo |
Bonita Montero <Bonita.Montero@gmail.com>: Feb 02 05:32PM +0100 Am 02.02.2017 um 03:09 schrieb Paul: > { > int a[K]; > } That's not legal C++-code. But you can use alloca in C++ to have a variable length array: #include <malloc.h> void makeArray( const int K ) { int *a = (int *)alloca( K * sizeof(int) ); } With almost any copiler you lose one register which becomes the frame -pointer because the stack-pointer is advanced a variable distance and the compiler would not be able to find back to the calling stack-frame without this frme-pointer. -- http://facebook.com/bonita.montero/ |
scott@slp53.sl.home (Scott Lurndal): Feb 02 04:47PM >In a very special situation and extra careful programmers - maybe. But >do you imagine how many bugs the average noob will create when writing >this kind of code? I'm not sure the audience here encompasses the "average noob". I think I'd rather have a programmer who had created such bugs and had learned to debug them and program correctly to avoid them, rather than a programmer who lets the language do all the work without understanding how the machine works, warts and all. |
Andrey Tarasevich <andreytarasevich@hotmail.com>: Feb 02 09:20AM -0800 On 2/1/2017 6:09 PM, Paul wrote: > Is the below code legal? No. > On the one hand, the array length seems constant > as required. The requirement is for the array size to be an Integral Constant Expression. A function parameter, even of const type, cannot participate in an Integral Constant Expression. -- Best regards, Andrey Tarasevich |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 02 12:00AM On 01/02/2017 22:57, Rick C. Hodgin wrote: [bullshit snipped] Fuck. Off. /Flibble |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 01 04:31PM -0800 Leigh, you have the right to respond in that way. My teaching to you is that there's a day coming when you'll find the cost of exercising that right is far more than you'll want to pay. It's much better to learn that lesson now. Thank you, Rick C. Hodgin |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 02 12:34AM On 02/02/2017 00:31, Rick C. Hodgin wrote: [bullshit snipped] I. Said. Fuck. Off. /Flibble |
karolak kolo <karolakkolo123@gmail.com>: Feb 01 06:54PM -0800 Well, here posts related to c++ have to be posted. However, Mr. Flibble you should kindly say that this should be not posted here instead of insulting, because posts like this are not making the world better. |
Jerry Stuckle <jstucklex@attglobal.net>: Feb 01 10:55PM -0500 On 2/1/2017 9:54 PM, karolak kolo wrote: > Well, here posts related to c++ have to be posted. However, Mr. Flibble you should kindly say that this should be not posted here instead of insulting, because posts like this are not making the world better. Because Rick has repeatedly refused to honor requests to stay on topic (C++), whether polite or otherwise. He's really no different than any other zealot. Fortunately, REAL Christians know where their teachings are appropriate and where they are not. But those who believe they are Christians but are actually driven by the Devil think their teachings are appropriate anywhere and any time. It's an insidious plan to drive people away from Christianity. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ================== |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 02 08:23AM -0800 It is the love of Jesus Christ, who made you and everything, that wants you to come to Him and ask forgiveness for your sin. Do you have sin? The standard is the Bible's teachings. His standards. If you have sin...you need to be forgiven. Jesus is the one who can forgive you. All you have to do is believe and ask Him. He forgives all who come to Him. No matter what you've done, or how much, or how often, or how recently, or to whom... Jesus WILL forgive you. http://www.libsf.org/misc/love.html Love you, Rick C. Hodgin |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 02 03:50PM +0100 On 01.02.2017 19:08, Mr Flibble wrote: > Doing such things makes C++ code harder to read not easier. Avoid > macros, period. Well, I wonder. I enjoy exploring things to see where and what it leads to, and here's some example (real) code – the `$xxx` names are macros: struct Argument { string name; string type; }; struct Function { string base_name; string result_type; vector<Argument> args; }; inline $function to_string( ref_<const Argument> arg ) -> string { return arg.type + " " + arg.name; } inline $function to_string( ref_<const Function> f ) -> string { string result = f.base_name; for( $each item : enumerated( f.args ) ) { if( not item.is_first() ) { result += ", "; } result += to_string( item.object() ); } if( n_items_in( f.args ) > 0 ) { result = ' ' + result + ' '; } result = '(' + result + ')'; return $case( f.result_type == "void", "void " + result ) $default( "inline auto " + result + " -> " + f.result_type ); } The readability goal I set here was to get rid of all `auto` (it really has a lot of meanings now, conceptually quite different meanings), and all `&` and `*` used as type builders, and all weird operator notation like `:?`, plus, support prefix `const` in general. I think, maybe inside C++ there's a more streamlined and readable language struggling to get out. Possibly. :) Maybe I should continue my exploration of Rust, though; I barely started... Cheers!, - Alf |
karolak kolo <karolakkolo123@gmail.com>: Feb 01 04:55PM -0800 I wrote a C++ container which I call "bucket", and basically it is a prototype of an array that can hold multiple types at the same time. It is used like this: bucket<N, types> example; //Declaring a bucket that can hold N items, and can support types listed after commas. For example bucket<55,int,float> could hold 55 elements of types float or int. example[i] = value; //Assigns a value to a cell of the bucket. Value of any type that was listed in the <> brackets is supported. value = (type)example[i] // assigns a value of a cell in the bucket to some variable. The type of the item retrieved has to be put in parentheses like that. (This will be improved in the future). The implementation can be found here: http://pastebin.com/fVMhqph8 Could this have any use? |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 01 06:59PM -0600 > parentheses like that. (This will be improved in the future). > The implementation can be found here: http://pastebin.com/fVMhqph8 > Could this have any use? What's wrong with an array or vector of boost::variant? /Flibble |
karolak kolo <karolakkolo123@gmail.com>: Feb 01 05:30PM -0800 I didn't know that exists, but still what would be the use of this? |
"Öö Tiib" <ootiib@hot.ee>: Feb 02 05:43AM -0800 On Thursday, 2 February 2017 03:31:01 UTC+2, karolak kolo wrote: > I didn't know that exists, but still what would be the use of this? Please quote to what you are answering, otherwise it is unclear what you mean by "that" or "this" above. I assume you mean 'std::variant', but if I'm wrong then discard the rest of this letter. The 'std::variant' will be added to C++ standard library this year and it is basically type safe union (never empty and no type punning possible): http://en.cppreference.com/w/cpp/utility/variant Requirements of it are widely based on implementation of 'boost::variant' (that has been around for more than decade): http://www.boost.org/doc/libs/1_63_0/doc/html/variant.html If custom class does not offer something special then most good programmers prefer standard library classes. It is so because standard library classes are generally more efficient, flexible, available for more platforms, better tested and/or faster fixed than custom classes. So the question was what is special in 'bucket<55,int,float>' that lacks in 'std::array<55, std::variant<int,float>>'? Of course if you are not aware of existence of 'boost::variant' like you say then it is likely that you can't answer why your 'bucket' is special compared to such alternatives. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 02 02:16AM +0100 On 01.02.2017 20:00, Tim Rentsch wrote: > very fast. Somewhere up around the 20'th or 30'th character, > the double loop algorithm starts to lose to the algorithms > that go through the string a (small) fixed number of times. Yeah I should (ideally) test again with better test data, not data where likely all values are unique. I mentioned Zipf's law when I posted that test, but somehow didn't trivially connect the dots. Grumble. Cheers!, - ALf |
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