mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Better std.algorithm.iteration.permutations error messages
This commit is contained in:
parent
43be08c3a7
commit
e1f7edae57
2 changed files with 18 additions and 2 deletions
8
changelog/permutation_assert_message.dd
Normal file
8
changelog/permutation_assert_message.dd
Normal file
|
@ -0,0 +1,8 @@
|
|||
Better static assert messages for `std.algorithm.iteration.permutations`
|
||||
|
||||
Until now, `permutations` used a template constraint to check if the passed types
|
||||
could be used. If they were not, it was very tedious to figure out why.
|
||||
|
||||
As the template constraint is not used for overload resolution
|
||||
the constrains are moved into static asserts with expressive error
|
||||
messages.
|
|
@ -7939,15 +7939,23 @@ See_Also:
|
|||
$(REF nextPermutation, std,algorithm,sorting).
|
||||
*/
|
||||
Permutations!Range permutations(Range)(Range r)
|
||||
if (isRandomAccessRange!Range && hasLength!Range)
|
||||
{
|
||||
static assert(isRandomAccessRange!Range, Range.stringof,
|
||||
" must be a RandomAccessRange");
|
||||
static assert(hasLength!Range, Range.stringof
|
||||
, " must have a length");
|
||||
|
||||
return typeof(return)(r);
|
||||
}
|
||||
|
||||
/// ditto
|
||||
struct Permutations(Range)
|
||||
if (isRandomAccessRange!Range && hasLength!Range)
|
||||
{
|
||||
static assert(isRandomAccessRange!Range, Range.stringof,
|
||||
" must be a RandomAccessRange");
|
||||
static assert(hasLength!Range, Range.stringof
|
||||
, " must have a length");
|
||||
|
||||
private size_t[] _indices, _state;
|
||||
private Range _r;
|
||||
private bool _empty;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue