digitalmars.D.learn - Nothrow front() when not empty()
- =?UTF-8?B?Tm9yZGzDtnc=?= (6/6) Jan 06 2016 At
- anonymous (10/16) Jan 06 2016 ----
- Alex Parrill (5/6) Jan 06 2016 Might want to use std.exception.assumeWontThrow instead
At https://github.com/D-Programming-Language/phobos/pull/3752 it would be nice if return !haystack.empty && haystack.front.unaryFun!pred was made nothrow. Is this possible somehow?
Jan 06 2016
On 06.01.2016 14:52, Nordlöw wrote:At https://github.com/D-Programming-Language/phobos/pull/3752 it would be nice if return !haystack.empty && haystack.front.unaryFun!pred was made nothrow. Is this possible somehow?---- try return !haystack.empty && pred(haystack.front); catch (Exception e) assert(false); ---- You must be 100% sure that the code cannot actually throw an Exception, of course. Alternatively, you could change `.front` to assert instead of throwing an Exception, considering it a programmer error when `.empty` is not checked before accessing `.front`.
Jan 06 2016
On Wednesday, 6 January 2016 at 14:17:51 UTC, anonymous wrote:try return !haystack.empty && pred(haystack.front);Might want to use std.exception.assumeWontThrow instead return assumeWontThrow(!haystack.empty && pred(haystack.front));
Jan 06 2016