Template constraints

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 14 09:52:55 PST 2015


On 2/14/15 9:06 AM, Tobias Pankrath wrote:
> I agree, but also for function should conditions that do not effect
> overloading go into static asserts.
>
> For example if I were to write an algorithm that works with forward
> ranges and can be optimized for random access ranges but needs
> assignable elements in any case:
>
> void foo(R)(R r) if(isForwardRange!R && !isRandomAccessRange!R)
> {
>      static assert(hasAssignableElements!R, "informative error msg");
> }
>
> void foo(R)(R r) if(isRandomAccessRange!R)
> {
>      static assert(hasAssignableElements!R, "informative error msg");
> }

That would impact cross-module overloading. -- Andrei


More information about the Digitalmars-d mailing list