- The unobtrusive initialization in C++17 - 6 Updates
- What's the point of std::queue::pop() if I can't store the result? - 5 Updates
- Stackoverflow - a fascist web-site. - 2 Updates
- The unobtrusive initialization in C++17 - 2 Updates
Victor Bazarov <v.bazarov@comcast.invalid>: Apr 10 01:07PM -0400 On 4/9/2016 10:30 PM, Stefan Ram wrote: > So is there anything wrong with: > auto p { ::std::make_pair( 0, 0 ) }; > ? There is nothing "wrong" with it. And if some old dog (whom you are trying to teach this new trick) says that it's unusual or ugly or odd or ..., you'll just need to find an explanation to demonstrate the *advantage* of using the new syntax over the old one. So start looking for it. Keep in mind that changing something for the sake if changing it is *not constructive*. V -- I do not respond to top-posted replies, please don't ask |
Daniel <danielaparker@gmail.com>: Apr 10 11:10AM -0700 > On 4/9/2016 10:30 PM, Stefan Ram wrote: > But then I remembered that I often saw: > auto p = ::std::make_pair( 0, 0 ); Somehow I doubt if you ever saw that, outside of your own code. Daniel |
"Öö Tiib" <ootiib@hot.ee>: Apr 10 11:41AM -0700 On Sunday, 10 April 2016 21:11:10 UTC+3, Daniel wrote: > > But then I remembered that I often saw: > > auto p = ::std::make_pair( 0, 0 ); > Somehow I doubt if you ever saw that, outside of your own code. It is possible he saw it somewhere. The 'std::pair<int,int> p(0, 0);' is both less to type and easier to read. The people who love to be verbose and incomprehensible also like to write a lot and to blog about it and so it is likely to see their odd writings often somewhere. |
Paavo Helde <myfirstname@osa.pri.ee>: Apr 10 11:49PM +0300 On 10.04.2016 21:41, 嘱 Tiib wrote: > verbose and incomprehensible also like to write a lot and to blog > about it and so it is likely to see their odd writings often > somewhere. I'm sure Daniel meant the colon noise overdose in ::std, that seems to be pretty unique to OP. Cheers Paavo |
"Öö Tiib" <ootiib@hot.ee>: Apr 10 02:15PM -0700 On Sunday, 10 April 2016 23:49:36 UTC+3, Paavo Helde wrote: > > somewhere. > I'm sure Daniel meant the colon noise overdose in ::std, that seems to > be pretty unique to OP. Oh. AFAIK also woodbrian is devoted follower of :: before std. He claims that it protects his middlewriter's code from some sort of evil and stupid users. |
Paavo Helde <myfirstname@osa.pri.ee>: Apr 11 12:41AM +0300 On 11.04.2016 0:15, Öö Tiib wrote: > Oh. AFAIK also woodbrian is devoted follower of :: before std. > He claims that it protects his middlewriter's code from some sort of > evil and stupid users. Oh, I see. It seems I should clear my killfile to have better overview of bad coding style habits. On a second thought, that might not be so great idea ;-) Cheers Paavo |
elmazzun <mazzocchiandrea24@gmail.com>: Apr 10 07:23AM -0700 Hi everybody, there is something that I don't understand about popping from std::queue. I pushed successfully a custom struct of mine in a queue, like this: data_packet pkt; // typedef'd struct of mine q.push(pkt); // push() goes fine What I don't get is how to store the result of a popped element from my queue, since it is "void pop()". I read about queue::front, which returns a reference to "the oldest element in the queue and the same element that is popped out from the queue when queue::pop is called." Well, if front() returns a reference&, I made like this: data_packet *pkt; if (!q.empty()) { pkt = q.front(); q.pop(); } but the compiler says: error: cannot convert 'data_pkt' to 'data_packet* {aka data_pkt*}' in assignment. I think it returns this error because I pushed in my queue a data_packet struct, not a pointer to it. But, how can I retrieve a struct from my queue and store it, not just pop() it and lose it? |
Daniel <danielaparker@gmail.com>: Apr 10 07:55AM -0700 On Sunday, April 10, 2016 at 10:24:10 AM UTC-4, elmazzun wrote: > q.push(pkt); // push() goes fine > What I don't get is how to store the result of a popped > element from my queue, since it is "void pop()". data_packet first = q.front(); q.pop(); > pkt = q.front(); > q.pop(); > } If you replaced data_packet *pkt; with data_packet& pkt; it would compile, but it wouldn't work, as the reference would be invalided by q.pop(); Daniel |
elmazzun <mazzocchiandrea24@gmail.com>: Apr 10 08:12AM -0700 > data_packet& pkt; > it would compile, but it wouldn't work, as the reference would be > invalided by q.pop(); That's what I was doing, indeed it compiled but the fields in my retrieved struct shows orrible numbers. Even commenting the pop() instruction did not make it work... |
"Öö Tiib" <ootiib@hot.ee>: Apr 10 08:49AM -0700 On Sunday, 10 April 2016 18:13:05 UTC+3, elmazzun wrote: > That's what I was doing, indeed it compiled but the fields in my > retrieved struct shows horrible numbers. > Even commenting the pop() instruction did not make it work... That sounds like your code has some more issues than that 'pop'. The logic is that if copy constructor of popped element throws during 'pop' then first the implementation of 'pop' and after that you will have quite bad situation. So no copies are made during 'pop'. Think about it. Therefore you should 'pop()' *after* you have done everything that you want with the element. Including (if you need to) copying or moving from it. After 'pop' the element is gone and destroyed. Debug versions of some implementations also fill the memory where it was with most unlikely garbage to ensure that it does not work and draws your attention. |
elmazzun <mazzocchiandrea24@gmail.com>: Apr 10 09:28AM -0700 You are right, I had to front() the struct from the queue and ONLY after I read the values in the retrieved struct pop() it. Thanks to both of you, this was so stupid...still learning, I'm from 2 years of C development and I still have to master C++. |
Vlad from Moscow <vlad.moscow@mail.ru>: Apr 10 03:27AM -0700 On Saturday, April 9, 2016 at 11:42:10 AM UTC+3, Bo Persson wrote: > bomb runs against swedish targets, but that doesn't make us being > against russians in general, just your current government policy. > Bo Persson Possibly I will dissapoint you but you think too primitively. It is you who is under the impression of the propaganda.:) I have my own brain.:) |
"Öö Tiib" <ootiib@hot.ee>: Apr 10 08:29AM -0700 On Sunday, 10 April 2016 13:27:58 UTC+3, Vlad from Moscow wrote: > Possibly I will dissapoint you but you think too primitively. It is you > who is under the impression of the propaganda.:) > I have my own brain.:) Yes, you have your totally brainwashed brain. It is likely pointless to speak to half-zombie like you but it is anyway worth to try, somewhere under that layer of brainwash may live spark of consciousness, who knows. Your hate is like tapeworm; your brainwashed brain may contain it but that can not infect me. |
ram@zedat.fu-berlin.de (Stefan Ram): Apr 10 02:30AM I wrote: auto p { ::std::make_pair( 0, 0 ) }; for C++17. But then I remembered that I often saw: auto p = ::std::make_pair( 0, 0 ); with an »equals« sign. So is there anything wrong with: auto p { ::std::make_pair( 0, 0 ) }; ? (I am trying to settle for a unobtrusive standard form for my initializations, and this form should be: auto name { initializationexpression }; and auto const name { initializationexpression }; .) |
ram@zedat.fu-berlin.de (Stefan Ram): Apr 10 03:04PM >data_packet *pkt; >if (!q.empty()) { >pkt = q.front(); A reference is not a pointer. »data_packet« needs some constructor or assignment operator, and then one can write data_packet pkt { q.font() }; /* C++17 */ or pkt = q.front(); or maybe even pkt = ::std::move( q.front() ); . Una referenza non è un puntatore. «data_packet» ha bisogna di un construttore o un operatore di assegnamento, e poi si può scrivere data_packet pkt { q.font() }; /* C++17 */ oppure pkt = q.front(); oppure magari pkt = ::std::move( q.front ); . |
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