tag:blogger.com,1999:blog-7551109856480446461.post1995920192218615796..comments2022-04-04T07:30:52.536+02:00Comments on kbok on obscure c++ nobody uses: Using reverse iterators with c++11 range-based "for" loopskbokhttp://www.blogger.com/profile/05101641675135136559noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-7551109856480446461.post-63752155598464759262013-12-18T20:54:17.858+01:002013-12-18T20:54:17.858+01:00Warning, you can end up with a dangling reference ...Warning, you can end up with a dangling reference if you use a temporary! Try replacing<br /><br /> std::string stressed = "stressed no tips";<br /> for(char c : reverse(stressed))<br /><br />with<br /><br /> for(char c : reverse(std::string("stressed no tips")))<br /><br />then it won't work (the string will be destructed before the first iteration, undefined behavior). That's annoying, since<br /><br /> for(char c : std::string("stressed no tips"))<br /><br />is valid. The fix is not easy, I guess you must treat rvalue references differently and store a container object (move from source)... Maybe boost::adaptors::reverse handles that...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-55342562824240152922013-09-27T11:48:47.267+02:002013-09-27T11:48:47.267+02:00change decltype( container.rbegin() ) to decltype(...change decltype( container.rbegin() ) to decltype( Cont().rbegin() )Unknownhttps://www.blogger.com/profile/06531767384905199206noreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-38553818077877227382013-08-13T03:39:31.112+02:002013-08-13T03:39:31.112+02:00This change seems to work in VS 2012
auto begin...This change seems to work in VS 2012<br /><br /> auto begin()-> decltype(container.rbegin()) { return container.rbegin(); }<br /> auto end() -> decltype(container.rend()) { return container.rend(); }<br />--davidAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-35812776355281208112012-11-08T20:56:59.983+01:002012-11-08T20:56:59.983+01:00@jwcacces: Fixed, thanks.@jwcacces: Fixed, thanks.kbokhttps://www.blogger.com/profile/05101641675135136559noreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-55511590540410044002012-10-24T19:45:38.380+02:002012-10-24T19:45:38.380+02:00In const_reverse_wrapper,
decltype(container.rend...In const_reverse_wrapper,<br /> decltype(container.rend()) end() { return container.rend(); }<br />should be:<br /> decltype(container.rend()) end() const { return container.rend(); }<br /><br />jwcaccesnoreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-40462461954084562552012-09-29T20:32:18.977+02:002012-09-29T20:32:18.977+02:00Visual C++ 2012 gives the error "C2228: left ...Visual C++ 2012 gives the error "C2228: left of '.rbegin' must have class/struct/union."<br /><br />Dang.Jive Dadsonhttps://www.blogger.com/profile/00777387059650449643noreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-66568096752119371872012-01-26T00:36:35.918+01:002012-01-26T00:36:35.918+01:00Thanks kbok!Thanks kbok!Stevehttps://www.blogger.com/profile/02912895180907594217noreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-39378163008140972452011-12-16T21:19:53.664+01:002011-12-16T21:19:53.664+01:00Hi Steve, sorry for the late answer. I added a &qu...Hi Steve, sorry for the late answer. I added a "about" page with licensing information. The code snippets are now in public domain.kbokhttps://www.blogger.com/profile/05101641675135136559noreply@blogger.comtag:blogger.com,1999:blog-7551109856480446461.post-42784839431515169662011-12-09T02:31:47.280+01:002011-12-09T02:31:47.280+01:00This looks very elegant. I would like to use this...This looks very elegant. I would like to use this code but I need a license from you. Can you please attach some non-GPL FOSS license?<br />Cheers!Stevehttps://www.blogger.com/profile/02912895180907594217noreply@blogger.com