{"action":"created","issue":{"url":"https://api.github.com/repos/CaseyCarter/cmcstl2/issues/214","repository_url":"https://api.github.com/repos/CaseyCarter/cmcstl2","labels_url":"https://api.github.com/repos/CaseyCarter/cmcstl2/issues/214/labels{/name}","comments_url":"https://api.github.com/repos/CaseyCarter/cmcstl2/issues/214/comments","events_url":"https://api.github.com/repos/CaseyCarter/cmcstl2/issues/214/events","html_url":"https://github.com/CaseyCarter/cmcstl2/issues/214","id":388924576,"node_id":"MDU6SXNzdWUzODg5MjQ1NzY=","number":214,"title":"Problem of reverse_view after filter_view","user":{"login":"adah1972","id":2137834,"node_id":"MDQ6VXNlcjIxMzc4MzQ=","avatar_url":"https://avatars1.githubusercontent.com/u/2137834?v=4","gravatar_id":"","url":"https://api.github.com/users/adah1972","html_url":"https://github.com/adah1972","followers_url":"https://api.github.com/users/adah1972/followers","following_url":"https://api.github.com/users/adah1972/following{/other_user}","gists_url":"https://api.github.com/users/adah1972/gists{/gist_id}","starred_url":"https://api.github.com/users/adah1972/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adah1972/subscriptions","organizations_url":"https://api.github.com/users/adah1972/orgs","repos_url":"https://api.github.com/users/adah1972/repos","events_url":"https://api.github.com/users/adah1972/events{/privacy}","received_events_url":"https://api.github.com/users/adah1972/received_events","type":"User","site_admin":false},"labels":[{"id":218483314,"node_id":"MDU6TGFiZWwyMTg0ODMzMTQ=","url":"https://api.github.com/repos/CaseyCarter/cmcstl2/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-12-08T13:59:08Z","updated_at":"2018-12-11T05:07:54Z","closed_at":"2018-12-11T05:07:55Z","author_association":"NONE","body":"I checked with range-v3, the following code had no problem (when cmcstl2 does not conflict with range-v3):\r\n\r\n```c++\r\n#include <range/v3/all.hpp>\r\n#include <experimental/ranges/algorithm>\r\n#include <experimental/ranges/iterator>\r\n#include <algorithm>\r\n#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    namespace std2 = std::experimental::ranges;\r\n    using namespace ranges::v3;\r\n    int v[] = {1, 7, 3, 6, 5, 2, 4, 8};\r\n    auto r = v\r\n        | view::filter([](int i) { return i % 2 == 0; })\r\n        | view::reverse;\r\n    copy(v, std2::ostream_iterator<int>(std::cout, \" \"));\r\n    std::cout << std::endl;\r\n    copy(r, std2::ostream_iterator<int>(std::cout, \" \"));\r\n    std::cout << std::endl;\r\n}\r\n```\r\n\r\nHowever, the equivalent std-ranges version does not work:\r\n\r\n```c++\r\n#include <experimental/ranges/algorithm>\r\n#include <experimental/ranges/iterator>\r\n#include <experimental/ranges/ranges>\r\n#include <algorithm>\r\n#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    namespace ranges = std::experimental::ranges;\r\n    int a[] = {1, 7, 3, 6, 5, 2, 4, 8};\r\n    //auto r = ranges::filter_view(ranges::reverse_view(a),\r\n    //                             [](int i) { return i % 2 == 0; });\r\n    auto r = ranges::reverse_view(\r\n        ranges::filter_view(a, [](int i) { return i % 2 == 0; }));\r\n    copy(a, ranges::ostream_iterator<int>(std::cout, \" \"));\r\n    std::cout << std::endl;\r\n    copy(r, ranges::ostream_iterator<int>(std::cout, \" \"));\r\n    std::cout << std::endl;\r\n}\r\n```\r\n\r\nI got invalid output followed by a segment fault. The commented-out code can work without problems.\r\n\r\nRange-v3 has no problems with either order. I am wondering whether my code is non-conformant, or there is a bug somewhere in cmcstl2?"},"comment":{"url":"https://api.github.com/repos/CaseyCarter/cmcstl2/issues/comments/446074251","html_url":"https://github.com/CaseyCarter/cmcstl2/issues/214#issuecomment-446074251","issue_url":"https://api.github.com/repos/CaseyCarter/cmcstl2/issues/214","id":446074251,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NjA3NDI1MQ==","user":{"login":"CaseyCarter","id":456873,"node_id":"MDQ6VXNlcjQ1Njg3Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/456873?v=4","gravatar_id":"","url":"https://api.github.com/users/CaseyCarter","html_url":"https://github.com/CaseyCarter","followers_url":"https://api.github.com/users/CaseyCarter/followers","following_url":"https://api.github.com/users/CaseyCarter/following{/other_user}","gists_url":"https://api.github.com/users/CaseyCarter/gists{/gist_id}","starred_url":"https://api.github.com/users/CaseyCarter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaseyCarter/subscriptions","organizations_url":"https://api.github.com/users/CaseyCarter/orgs","repos_url":"https://api.github.com/users/CaseyCarter/repos","events_url":"https://api.github.com/users/CaseyCarter/events{/privacy}","received_events_url":"https://api.github.com/users/CaseyCarter/received_events","type":"User","site_admin":false},"created_at":"2018-12-11T05:07:54Z","updated_at":"2018-12-11T05:07:54Z","author_association":"OWNER","body":"> > I am wondering whether my code is non-conformant, or there is a bug somewhere in cmcstl2?\r\n> \r\n> This is almost certainly my bug and not yours.\r\n\r\nThe bug is in `filter_view::__iterator::operator--`:\r\n```diff\r\n constexpr __iterator& operator--() requires BidirectionalRange<V>\r\n {\r\n     do\r\n         --current_;\r\n-    while(__stl2::invoke(parent_->pred_.get(), *current_));\r\n+    while(!__stl2::invoke(parent_->pred_.get(), *current_));\r\n     return *this;\r\n }\r\n```\r\nIt's searching for the previous element that *doesn't* satisfy the predicate rather than the previous element that *does*. I fixed this months ago in the Ranges proposal, and assumed it was a typo that had been introduced during all the editing work. It never occurred to me that the bug might have been copied directly from the implementation.\r\n\r\nFixed in bf7206f7569cd7a2ca90022fb812ac79e3a79baa."}}
{"actor":{"display_login":"CaseyCarter"}}