{"action":"created","issue":{"url":"https://api.github.com/repos/ericniebler/range-v3/issues/579","repository_url":"https://api.github.com/repos/ericniebler/range-v3","labels_url":"https://api.github.com/repos/ericniebler/range-v3/issues/579/labels{/name}","comments_url":"https://api.github.com/repos/ericniebler/range-v3/issues/579/comments","events_url":"https://api.github.com/repos/ericniebler/range-v3/issues/579/events","html_url":"https://github.com/ericniebler/range-v3/issues/579","id":213731784,"number":579,"title":"compiler loops on range recursion","user":{"login":"etam","id":220752,"avatar_url":"https://avatars2.githubusercontent.com/u/220752?v=3","gravatar_id":"","url":"https://api.github.com/users/etam","html_url":"https://github.com/etam","followers_url":"https://api.github.com/users/etam/followers","following_url":"https://api.github.com/users/etam/following{/other_user}","gists_url":"https://api.github.com/users/etam/gists{/gist_id}","starred_url":"https://api.github.com/users/etam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etam/subscriptions","organizations_url":"https://api.github.com/users/etam/orgs","repos_url":"https://api.github.com/users/etam/repos","events_url":"https://api.github.com/users/etam/events{/privacy}","received_events_url":"https://api.github.com/users/etam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-03-13T10:52:18Z","updated_at":"2017-03-14T12:40:55Z","closed_at":null,"body":"One day I came on the https://www.haskell.org/ and found this little code (last line is mine):\r\n```\r\nprimes = filterPrime [2..] \r\n  where filterPrime (p:xs) = \r\n          p : filterPrime [x | x <- xs, x `mod` p /= 0]\r\n\r\nmain = print $ take 10 primes\r\n```\r\n\r\nSo I tried to reimplement this using range-v3. This is what I came up with:\r\n\r\n```\r\n#include <iostream>\r\n#include <range/v3/all.hpp>\r\n\r\nauto prepend(auto v, auto rng)\r\n{\r\n  return ranges::view::concat(ranges::view::single(v), rng);\r\n}\r\n\r\nauto filterPrime(auto rng)\r\n{\r\n  const auto p = ranges::front(rng);\r\n  return prepend(\r\n    p,\r\n    filterPrime(rng | ranges::view::tail | ranges::view::remove_if(\r\n      [=](auto x){ return x % p == 0; }\r\n    ))\r\n  );\r\n}\r\n\r\nauto primes()\r\n{\r\n  return filterPrime(ranges::view::ints(2));\r\n}\r\n\r\nint main()\r\n{\r\n  ranges::copy(primes() | ranges::view::take(10),\r\n               ranges::ostream_iterator<>(std::cout, \" \"));\r\n  std::cout << '\\n';\r\n}\r\n```\r\n\r\nThe problem is that both gcc 6.3.1 and clang 3.9.1 loops infinitely on this code.\r\n\r\nI think it's because they're trying to find out the return type of filterPrime function.\r\n\r\nCould this be fixed by adding some explicit types instead of auto? Or is there a type-erasing view, that will prevent the return type explosion?"},"comment":{"url":"https://api.github.com/repos/ericniebler/range-v3/issues/comments/286408905","html_url":"https://github.com/ericniebler/range-v3/issues/579#issuecomment-286408905","issue_url":"https://api.github.com/repos/ericniebler/range-v3/issues/579","id":286408905,"user":{"login":"gnzlbg","id":904614,"avatar_url":"https://avatars3.githubusercontent.com/u/904614?v=3","gravatar_id":"","url":"https://api.github.com/users/gnzlbg","html_url":"https://github.com/gnzlbg","followers_url":"https://api.github.com/users/gnzlbg/followers","following_url":"https://api.github.com/users/gnzlbg/following{/other_user}","gists_url":"https://api.github.com/users/gnzlbg/gists{/gist_id}","starred_url":"https://api.github.com/users/gnzlbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnzlbg/subscriptions","organizations_url":"https://api.github.com/users/gnzlbg/orgs","repos_url":"https://api.github.com/users/gnzlbg/repos","events_url":"https://api.github.com/users/gnzlbg/events{/privacy}","received_events_url":"https://api.github.com/users/gnzlbg/received_events","type":"User","site_admin":false},"created_at":"2017-03-14T12:40:55Z","updated_at":"2017-03-14T12:40:55Z","body":"@etam is using `view::tail` for that (which I like more in this case than `view::drop(1)`). I haven't been able to come up with a clean solution that removes the `any_range<int>`s though, so if somebody figures out a clean way to do that, please speak up :D "}}
{"actor":{"display_login":"gnzlbg"}}