www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why four definitions of std.meta.Replace?

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
/**
  * Returns an `AliasSeq` created from TList with the first occurrence
  * of type T, if found, replaced with type U.
  */
template Replace(T, U, TList...)
{
     alias Replace = GenericReplace!(T, U, TList).result;
}

/// Ditto
template Replace(alias T, U, TList...)
{
     alias Replace = GenericReplace!(T, U, TList).result;
}

/// Ditto
template Replace(T, alias U, TList...)
{
     alias Replace = GenericReplace!(T, U, TList).result;
}

/// Ditto
template Replace(alias T, alias U, TList...)
{
     alias Replace = GenericReplace!(T, U, TList).result;
}

Why all this? Delete it, rename GenericReplace to Replace, and call it a 
day.

I reckon documentation won't be as nice because GenericReplace just 
takes an ellipsis? Was this the rationale? I don't think it's much of a 
problem, and if we decide it is, version(StdDdoc) takes care of that 
with less aggravation.

This pattern is all over std.meta, and it's bad.
May 24 2020
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 25 May 2020 at 01:43:01 UTC, Andrei Alexandrescu wrote:
 Why all this?
Until semi-recently, you could not pass a built-in basic type to an `alias` param. I don't recall when that was changed, I think it last year, but surely the Phobos implementation predates that enhancement. And you could use the ... before but that was perhaps too permissive. Or maybe the original author just didn't like that style. But with alias accepting keyword types now, I imagine a LOT of phobos could be simplified to use it.
May 24 2020