On Thu, Feb 27, 2014 at 04:12:02AM +0000, Adam D. Ruppe wrote:
[...]
> Any better ideas? I just sometimes get frustrated, especially with
> more complex ranges, when the duck type doesn't work and it is hard
> to find why. This is one idea.
> 
> On a similar vein, template constraints can lead to some ugly
> messages. Why didn't it match any of them? But I think this has to
> be a compiler change and might spam all kinds of nonsense, whereas
> tweaking isInputRange etc. is a fairly conservative change that I
> think will help a lot too.

We've talked about this before. I proposed the idea that sig constraints
should be used to pick up *all* "logical" types that you want to
support, and static ifs used to narrow down which subset of the accepted
logical types is actually implemented for. Example:

        auto sort(R)(R range)
                if (isInputRange!R) // N.B. we accept *any* range:
                                // "sort a range" is the logical
                                // category we cover for.
        {
                // N.B. our implementation can only handle random access
                // ranges, so use static if.
                static if (!isRandomAccessRange!R)
                        static assert(0, "Don't know how to sort a non-random 
access range");
                else {
                        // implementation here
                }
        }

But it's not perfect, though.


T

-- 
Real men don't take backups. They put their source on a public FTP-server and 
let the world mirror it. -- Linus Torvalds

Reply via email to