- xor the elements of two vectors - 21 Updates
- [Jesus Loves You] Israel born in 1948 - 1 Update
- C C++ Training in Chennai - 1 Update
bitrex <user@example.net>: Jun 05 08:02PM -0400 I'm looking for the efficient/modern C++ way to bitwise xor element-wise the objects contained in two std::vectors, and stuff the resultant values into new vector of the same length as the original two. I think this can be done with a lambda function? and a mapping function on the vectors but don't immediately know the procedure I would use. Thank you |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 06 03:18AM +0200 On 06.06.2019 02:02, bitrex wrote: > values into new vector of the same length as the original two. > I think this can be done with a lambda function? and a mapping function > on the vectors but don't immediately know the procedure I would use. Lambdas can be used for anything but why not just use a simple loop. KISS, Keep It Simple, Stupid. Off the cuff: using Size = ptrdiff_t; template< class Item > auto xor_of( const vector<Item>& a, const vector<Item>& b ) -> vector<Item> { vector<Item>& short_vec = (a.size() < b.size()? a : b); vector<Item>& long_vec = (a.size() < b.size()? b : a); vector<Item> result( short.size() ); for( Size i = 0, n = short.size(); i < n; ++i ) { result[i] = short_vec[i] ^ long_vec[i]; } for( Size i = short_vec.size(), n = long_vec.size(); i < n; ++i ) { result[i] = long_vec[i]; } return result; } Cheers!, - Alf |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 06 03:18AM +0200 On 06.06.2019 03:18, Alf P. Steinbach wrote: > } > Cheers!, > - Alf Oh, the result should be of the longest size, not shortest. Anyway. Cheers!, - Alf |
bitrex <user@example.net>: Jun 05 09:45PM -0400 On 6/5/19 9:18 PM, Alf P. Steinbach wrote: > } > Cheers!, > - Alf Thank you, I'm curious why is ptrdiff_t used in this context instead of size_t? |
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Jun 05 08:17PM -0700 On 6/5/2019 5:02 PM, bitrex wrote: > I think this can be done with a lambda function? and a mapping function > on the vectors but don't immediately know the procedure I would use. > Thank you For what its worth, and is probably off topic... One can get some interesting xors using the xy plane. Now, afaict, this can be extended to fill the 3d space. Here is a very simple, crude real time example: https://www.shadertoy.com/view/4lffzM It shows the patterns on the xy xor'ing playground, so to speak... |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 06 09:06AM +0200 On 06.06.2019 03:45, bitrex wrote: >> - Alf > Thank you, I'm curious why is ptrdiff_t used in this context instead of > size_t? A general rule-of-thumb: to avoid unsigned thumbs /for numbers/, but do use them for bit-level stuff. Mainly the rationale of that rule is that the promotion rules in modern C and C++, which in C++ guarantee that e.g. std::string( "Hello" ).length() < -2 ... makes code that uses unsigned types used for numbers very attractive to bugs. Sort of like making a sugar trail into the house and leaving the door open. Cheers!, - Alf |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 06 09:42AM +0200 On 06.06.2019 09:06, Alf P. Steinbach wrote: > to avoid unsigned thumbs /for numbers/, Well I meant to write "types". My text generation subsystem works in mysterious ways. Cheers!, - Alf |
David Brown <david.brown@hesbynett.no>: Jun 06 10:57AM +0200 On 06/06/2019 09:42, Alf P. Steinbach wrote: > On 06.06.2019 09:06, Alf P. Steinbach wrote: >> to avoid unsigned thumbs /for numbers/, > Well I meant to write "types". I thought it made perfect sense, given that it was a rule of thumbs! |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 06 05:04AM -0700 On Wednesday, June 5, 2019 at 11:17:30 PM UTC-4, Chris M. Thomasson wrote: > https://www.shadertoy.com/view/4lffzM It looks more like a video game screen if you change this: int xy_xor = (x + iFrame/2) ^ (y*2); You can just see the Farmville plots of land down there. :-) -- Rick C. Hodgin |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 06 01:15PM On Thu, 2019-06-06, bitrex wrote: > values into new vector of the same length as the original two. > I think this can be done with a lambda function? and a mapping function > on the vectors but don't immediately know the procedure I would use. The function would be xor(a, b) -- is there a std::xor already? The mapping would be one of the variants of std::transform. Untested: std::transform(begin(vector1), end(vector1), begin(vector2), begin(dest), xor); You need to make room in 'dest' first, and check that vector2 is at least as large as vector1. Check the details at e.g. cppreference.com. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
leigh.v.johnston@googlemail.com: Jun 06 06:50AM -0700 On Thursday, June 6, 2019 at 2:18:12 AM UTC+1, Alf P. Steinbach wrote: > } > return result; > } If you are a proponent KISS then why aren't *you* keeping it simple by using auto return type when you don't have to, stupid? /Leigh |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 06 06:42PM +0200 >> return result; >> } > If you are a proponent KISS then why aren't *you* keeping it simple by using auto return type when you don't have to, stupid? Trailing return type syntax is generally simpler than the old syntax. For example, instead of MyLongClassName::Blah MyLongClassName::foo( Blah x ) ... you can write just auto MyLongClassName::foo( Blah x ) -> Blah Same rule for return type spec and argument spec = simpler, and shorter. It's also simpler in a number of other cases, e.g. consider a function returning a reference to an array. Cheers!, - Alf |
"Öö Tiib" <ootiib@hot.ee>: Jun 06 10:05AM -0700 On Thursday, 6 June 2019 19:43:08 UTC+3, Alf P. Steinbach wrote: > Same rule for return type spec and argument spec = simpler, and shorter. > It's also simpler in a number of other cases, e.g. consider a function > returning a reference to an array. Yes, it was what I liked in Fortran, Pascal and Ada and disliked in C. Also several popular modern C-like languages (like Rust, Swift, Kotlin) have corrected it back to that logical way. Starting from scratch I would consider it. However most things are done using tons of already existing code and libraries and also majority of good C++ programmers are aging and conservative. One does not want to have inconsistent style all over the code base. So it is perhaps tricky to switch for both practical and political reasons. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jun 06 06:39PM +0100 On 06/06/2019 17:42, Alf P. Steinbach wrote: > Same rule for return type spec and argument spec = simpler, and shorter. > It's also simpler in a number of other cases, e.g. consider a function > returning a reference to an array. However in *most* cases (including the case you posted) the version with auto is longer/more complex than the equivalent version without auto so I am sorry Alf but your argument simply doesn't wash. You even use it for main() but I think you do that just to piss people off. One should only use auto return when there is a clear need for it. STOP CAUSING PANIC. /Flibble -- "Talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jun 06 06:40PM +0100 On 06/06/2019 13:04, Rick C. Hodgin wrote: > It looks more like a video game screen if you change this: > int xy_xor = (x + iFrame/2) ^ (y*2); > You can just see the Farmville plots of land down there. :-) And Satan invented fossils, yes? /Flibble -- "Talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 06 10:55AM -0700 On Thursday, June 6, 2019 at 1:40:51 PM UTC-4, Mr Flibble wrote: > And Satan invented fossils, yes? Nope. But, he does convince people to be hateful to those who bear them no harm whatsoever. He causes amazing people made in the very image and likeness of God to set all that aside, to set their intelligence aside, and switchover to the mental equivalence of a five-year old's running around in circles away from their mommy screaming "blah blah blah blah blah" mode ... intellectually. You have demonstrated quite the personage, Leigh. Vulgar, obscene, profane, mean, belittling, bullying, arrogant, prideful, and you hide behind masks (posting as "Mr. Flibble" rather than Leigh). Are you ashamed of your own identity? You want to be someone else? There is peace in knowing Jesus Christ. You realize who you are, why you need to repent and ask forgiveness, and then He cleanses you of your unrighteousness before God. It fills you with calm and joy on the inside like none other. -- Rick C. Hodgin |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jun 06 07:45PM +0100 On 06/06/2019 18:55, Rick C. Hodgin wrote: > why you need to repent and ask forgiveness, and then He cleanses > you of your unrighteousness before God. It fills you with calm and > joy on the inside like none other. Nonsense. A) Your bible is false. B) Your god the existence of which is predicated on your bible being true is, given (A), also false. /Flibble -- "Talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 06 12:00PM -0700 On Thursday, June 6, 2019 at 2:45:21 PM UTC-4, Mr Flibble wrote: > A) Your bible is false. > B) Your god the existence of which is predicated on your bible being true > is, given (A), also false. Alright. I want to get in on this too, Leigh. It looks like fun. 2 + 2 = 5 Okay ... just so I don't waste my time ... how many times will I have to post this over and over before it becomes true? Wait! Wait. No. Perhaps that's the wrong question. Okay. In estimating your attempts at making your false statement come true to date, I know it's at least a few hundred. Maybe a few thousand?? So, I guess the better question would be: How long until YOUR false statement becomes true? -- Rick C. Hodgin |
legalize+jeeves@mail.xmission.com (Richard): Jun 06 08:15PM [Please do not mail me a copy of your followup] Jorgen Grahn <grahn+nntp@snipabacken.se> spake the secret code > begin(vector2), > begin(dest), > xor); This, yes, this is just what I was going to post :-) >You need to make room in 'dest' first, [...] Or you can use a back_inserter from <iterator>: std::transform(begin(vector1), end(vector1), begin(vector2), back_inserter(dest), xor); -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Jun 06 02:41PM -0700 On 6/6/2019 10:40 AM, Mr Flibble wrote: >> int xy_xor = (x + iFrame/2) ^ (y*2); >> You can just see the Farmville plots of land down there. :-) > And Satan invented fossils, yes? This is about having fun with XOR... No? |
jameskuyper@alumni.caltech.edu: Jun 06 03:38PM -0700 On Thursday, June 6, 2019 at 9:15:36 AM UTC-4, Jorgen Grahn wrote: ... > The function would be xor(a, b) -- is there a std::xor already? There's std::bit_xor. xor is a token in it's own right (5.5p2), so it can't be used as an identifier. |
Peter Cheung <mcheung63@gmail.com>: Jun 06 02:35PM -0700 Mr Flibble於 2019年6月6日星期四 UTC+8上午5時26分12秒寫道: > that is not our fault. It's not right, it's utterly, utterly evil." > "Why should I respect a capricious, mean-minded, stupid God who creates a > world that is so full of injustice and pain. That's what I would say." does he has a brain disease? |
"Softlogic Academy Pvt. Ltd" <softlogicseo@gmail.com>: Jun 06 06:26AM -0700 C is also referred as function oriented language as even input and output concepts are declared in terms of functions such as printf() scanf() etc., It is also a general purpose programming language Another limitation of C programming language is that it can never be defined within structures. Moreover, it does not support certain features such as name-space, virtual functions, friend functions, does not support exception or error handling and reference variables. Learn C and C++ program in Chennai and Get Knowledge through SLA trainees, Register for a Best C C++ Training in Chennai https://www.slajobs.com/c-c-plus-plus-training-in-chennai/ |
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