Better std.algorithm.iteration.permutations error messages

This commit is contained in:
Robert burner Schadek 2023-05-25 22:37:14 +02:00 committed by The Dlang Bot
parent 43be08c3a7
commit e1f7edae57
2 changed files with 18 additions and 2 deletions

View 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.

View file

@ -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;