Merge pull request #8685 from burner/filter_static_assert_message

Better std.algorithm.iteration.joiner error messages
This commit is contained in:
Razvan Nitu 2023-02-21 18:56:26 +08:00 committed by GitHub
commit b77c739643
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -0,0 +1,8 @@
Better static assert messages for `std.algorithm.iteration.joiner`
Up until now `filter` used a template constraint to check if the passed Data
could be used. If it were not, it was very tedious to figure out why.
As the template constraint is not used to overload the symbol template
function, the constrains are move into static asserts with expressive error
messages.

View file

@ -2969,10 +2969,24 @@ iterated from the back to the front, the separator will still be consumed from
front to back, even if it is a bidirectional range too.
*/
auto joiner(RoR, Separator)(RoR r, Separator sep)
if (isInputRange!RoR && isInputRange!(ElementType!RoR)
&& isForwardRange!Separator
&& is(ElementType!Separator : ElementType!(ElementType!RoR)))
{
static assert(isInputRange!RoR, "The type of RoR '", RoR.stringof
, " must be an InputRange (isInputRange!", RoR.stringof, ").");
static assert(isInputRange!(ElementType!RoR), "The ElementyType of RoR '"
, ElementType!(RoR).stringof, "' must be an InputRange "
, "(isInputRange!(ElementType!(", RoR.stringof , "))).");
static assert(isForwardRange!Separator, "The type of the Seperator '"
, Seperator.stringof, "' must be a ForwardRange (isForwardRange!("
, Seperator.stringof, ")).");
static assert(is(ElementType!Separator : ElementType!(ElementType!RoR))
, "The type of the elements of the separator range does not match "
, "the type of the elements that are joined. Separator type '"
, ElementType!(Separator).stringof, "' is not implicitly"
, "convertible to range element type '"
, ElementType!(ElementType!RoR).stringof, "' (is(ElementType!"
, Separator.stringof, " : ElementType!(ElementType!", RoR.stringof
, "))).");
static struct Result
{
private RoR _items;