A Briefer Syntax for Using Concepts
Sergei Nosov via Digitalmars-d
digitalmars-d at puremagic.com
Wed May 7 05:47:28 PDT 2014
On Wednesday, 7 May 2014 at 11:57:51 UTC, w0rp wrote:
> Here is a question, is it possible for D, or any future
> language, to eventually take something like this...
>
> void foo(InputRange)(InputRange range)
> if(isInputRange!InputRange);
>
> ...and to instead be able to write it like this?
>
> void foo(InputRange range);
>
> Where the latter expands into something like the former, and
> InputRange is not a type. How to declare such a thing in the
> first place doesn't matter that much. There are many ways that
> could be done. I'm just wondering if the above is possible at
> all.
C++ concepts has similar syntax.
http://isocpp.org/blog/2013/02/concepts-lite-constraining-templates-with-predicates-andrew-sutton-bjarne-s
template<Sortable Cont>
void sort(Cont& container);
I don't think making InputRange behave as you suggest in void
foo(InputRange range); is a valid options, since - how do you
handle the situation when you want to accept 2 InputRanges of
possibly distinct types?
void foo(InputRange range1, InputRange range2); // how to specify
that InputRange should be exactly the same type? or possibly
distinct types?
More information about the Digitalmars-d
mailing list