{"action":"created","issue":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3288","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3288/labels{/name}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3288/comments","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3288/events","html_url":"https://github.com/D-Programming-Language/phobos/pull/3288","id":77023159,"number":3288,"title":"Struct Returned findSplit*() with implicit bool conversion","user":{"login":"nordlow","id":829407,"avatar_url":"https://avatars.githubusercontent.com/u/829407?v=3","gravatar_id":"","url":"https://api.github.com/users/nordlow","html_url":"https://github.com/nordlow","followers_url":"https://api.github.com/users/nordlow/followers","following_url":"https://api.github.com/users/nordlow/following{/other_user}","gists_url":"https://api.github.com/users/nordlow/gists{/gist_id}","starred_url":"https://api.github.com/users/nordlow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nordlow/subscriptions","organizations_url":"https://api.github.com/users/nordlow/orgs","repos_url":"https://api.github.com/users/nordlow/repos","events_url":"https://api.github.com/users/nordlow/events{/privacy}","received_events_url":"https://api.github.com/users/nordlow/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-05-16T11:58:20Z","updated_at":"2015-05-19T14:59:33Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3288","html_url":"https://github.com/D-Programming-Language/phobos/pull/3288","diff_url":"https://github.com/D-Programming-Language/phobos/pull/3288.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/3288.patch"},"body":"This enables the following useful syntax in pattern matching:\r\n\r\n```D\r\nif (const split = line.findSplit(`-`))\r\n{\r\n    // do something with split\r\n}\r\n```\r\n\r\ninstead of current\r\n\r\n```D\r\nconst split = line.findSplit(`-`)\r\nif (!split[1].empty)\r\n{\r\n}\r\n```\r\n\r\nfor the Phobos algorithms `findSplit`, `findSplitBefore` and `findSplitAfter`.\r\n\r\nSee also discussion at: http://forum.dlang.org/thread/etttlwazcguwpaltyrps@forum.dlang.org#post-tbnvyqawcqmccvociwrr:40forum.dlang.org\r\n\r\nModule `std.algorithm` compiles and tests ok. However compilation of `std.traits` which in turn uses `std.typecons` fails as\r\n\r\n```\r\n../std/typecons.d(605,47): Error: reinterpreting cast from inout(string)* to inout(Tuple!(string, string, string))* is not supported in CTFE\r\ntraits.d(534,27):        called from here: findSplit(s, \"(\").asTuple._Tuple_super()\r\ntraits.d(536,45):        called from here: adjustIdent(\"std\")\r\ntraits.d(524,29): Error: template instance std.traits.fqnSym!(std) error instantiating\r\ntraits.d(524,29):        instantiated from here: fqnSym!(traits)\r\ntraits.d(446,35):        instantiated from here: fqnSym!(fullyQualifiedName)\r\ntraits.d(452,19):        instantiated from here: fullyQualifiedName!(fullyQualifiedName)\r\ntraits.d(524,29): Error: template instance std.traits.fqnSym!(QualifiedNameTests) error instantiating\r\ntraits.d(707,31):        instantiated from here: fqnSym!(Inner)\r\ntraits.d(444,35):        instantiated from here: fqnType!(Inner, false, false, false, false)\r\ntraits.d(550,19):        instantiated from here: fqn!(Inner)\r\ntraits.d(446,35): Error: template instance std.traits.fqnSym!(func) error instantiating\r\ntraits.d(551,19):        instantiated from here: fqn!(func)\r\ntraits.d(707,31): Error: template instance std.traits.fqnSym!(Data!int, Data, int) error instantiating\r\ntraits.d(444,35):        instantiated from here: fqnType!(Data!int, false, false, false, false)\r\ntraits.d(552,19):        instantiated from here: fqn!(Data!int)\r\ntraits.d(446,35): Error: template instance std.traits.QualifiedNameTests.Data!int.Data.fqnSym!(x) error instantiating\r\ntraits.d(553,19):        instantiated from here: fqn!(x)\r\ntraits.d(446,35): Error: template instance std.traits.fqnSym!(tfunc, tfunc, int[]) error instantiating\r\ntraits.d(554,19):        instantiated from here: fqn!(tfunc)\r\n../std/typecons.d(605,47): Error: reinterpreting cast from inout(string)* to inout(Tuple!(string, string, string))* is not supported in CTFE\r\ntraits.d(534,27):        called from here: findSplit(s, \"(\").asTuple._Tuple_super()\r\ntraits.d(536,45):        called from here: adjustIdent(\"object\")\r\ntraits.d(524,29): Error: template instance std.traits.fqnSym!(object) error instantiating\r\ntraits.d(707,31):        instantiated from here: fqnSym!(Object)\r\ntraits.d(444,35):        instantiated from here: fqnType!(Object, false, false, false, false)\r\ntraits.d(510,33):        instantiated from here: fullyQualifiedName!(Object)\r\ntraits.d(518,48):        ... (1 instantiations, -v to show) ...\r\ntraits.d(446,35):        instantiated from here: fqnSym!(__T4InstTC6ObjectZ, Inst, Object)\r\ntraits.d(555,19):        instantiated from here: fqn!(__T4InstTC6ObjectZ)\r\ntraits.d(446,35): Error: template instance std.traits.fqnSym!(x) error instantiating\r\n\r\nComint exited abnormally with code 1 at Sat May 16 14:11:40\r\n```\r\n\r\nIt seems CTFE-evaluation of `findSplit` fails with my patch. Is this fixable?"},"comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments/103537671","html_url":"https://github.com/D-Programming-Language/phobos/pull/3288#issuecomment-103537671","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3288","id":103537671,"user":{"login":"andralex","id":566679,"avatar_url":"https://avatars.githubusercontent.com/u/566679?v=3","gravatar_id":"","url":"https://api.github.com/users/andralex","html_url":"https://github.com/andralex","followers_url":"https://api.github.com/users/andralex/followers","following_url":"https://api.github.com/users/andralex/following{/other_user}","gists_url":"https://api.github.com/users/andralex/gists{/gist_id}","starred_url":"https://api.github.com/users/andralex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andralex/subscriptions","organizations_url":"https://api.github.com/users/andralex/orgs","repos_url":"https://api.github.com/users/andralex/repos","events_url":"https://api.github.com/users/andralex/events{/privacy}","received_events_url":"https://api.github.com/users/andralex/received_events","type":"User","site_admin":false},"created_at":"2015-05-19T14:59:33Z","updated_at":"2015-05-19T14:59:33Z","body":"Yes, `Result` is fine. A pattern I've used is to call them `Voldemort` since the word has entered the D vernacular so it's evocative enough. `static` ensures the struct has no environment pointer. The duplication is minor so I'd go with it instead of factoring a type we then need to worry about."}}