foo( concept-name [optional type-name] parameter-name )

64 views
Skip to first unread message

Cleiton Santoia

unread,
May 10, 2018, 2:04:42 AM5/10/18
to SG8 - Concepts



I was reading conceps proposal, and at "5.4" appear the interesting "foo(Even int i)", from P0791

Instead of pushing contracts, the same syntax may be used for disambiguation in "same type" x "different types"


foo(EqualyComparable e1, EqualyComparable e2);  //e1 and e2 may have (by default) different types ? ( I´m open to discuss )
foo
(EqualyComparable T e1, EqualyComparable T e2);  //e1 and e2 must have same type, and it´s called "T"
foo
(EqualyComparable T1 e1, EqualyComparable T2 e2);  //e1 and e2 definitely may have different types, "T1" and "T2" respectively



Somebody already thought about that ?


BR
Cleiton

Richard Smith

unread,
May 10, 2018, 5:46:13 PM5/10/18
to conc...@isocpp.org
Some discussed (but perhaps not in any paper) variants of the adjective syntax would allow this:

auto foo(EqualityComparable auto a, EqualityComparable auto b) // a and b can have different types
auto foo(EqualityComparable typename T1 a, EqualityComparable typename T2 b) // verbose but equivalent to the previous declaration

auto foo(EqualityComparable typename T a, T b) // a and b have the same type
auto foo(EqualityComparable typename T a, EqualityComparable T b) // redundant but equivalent to the previous declaration

Roland Bock

unread,
May 11, 2018, 3:08:41 AM5/11/18
to conc...@isocpp.org
On 2018-05-10 23:46, 'Richard Smith' via SG8 - Concepts wrote:
> On Wed, 9 May 2018 at 23:04, Cleiton Santoia <cleiton...@gmail.com
> <mailto:cleiton...@gmail.com>> wrote:
>
> I was reading conceps
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0745r0.pdf> proposal, and
> at "5.4" appear the interesting "foo(Even int i)", from P0791
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0791r0.pdf>
>
> Instead of pushing contracts, the same syntax may be used for
> disambiguation in "same type" x "different types"
>
>
> |
> foo(EqualyComparablee1,EqualyComparablee2); //e1 and e2 may have (by
> default) different types ? ( I´m open to discuss )
> foo(EqualyComparableT e1,EqualyComparableT e2); //e1 and e2 must
> have same type, and it´s called "T"
> foo(EqualyComparableT1 e1,EqualyComparableT2 e2); //e1 and e2
> definitely may have different types, "T1" and "T2" respectively
>
> |
>
>
> Somebody already thought about that ?
>
>
> Some discussed (but perhaps not in any paper) variants of the adjective
> syntax would allow this:
>
> auto foo(EqualityComparable auto a, EqualityComparable auto b) // a and
> b can have different types
> auto foo(EqualityComparable typename T1 a, EqualityComparable typename
> T2 b) // verbose but equivalent to the previous declaration
>
> auto foo(EqualityComparable typename T a, T b) // a and b have the same type
> auto foo(EqualityComparable typename T a, EqualityComparable T b) //
> redundant but equivalent to the previous declaration

How would this work for variadic templates?

I assume:
auto foo(EqualityComparable auto... as) // as can have different types
auto foo(EqualityComparable typename T... as) // as have the same type

Richard Smith

unread,
May 11, 2018, 4:03:53 PM5/11/18
to conc...@isocpp.org
I would expect:

auto foo(EqualityComparable auto ...as) // as can have different types
auto foo(EqualityComparable typename T ...as) // error, pack expansion of 'as' doesn't expand any packs
auto foo(EqualityComparable typename ...T ...as) // as have the same type

(The idea is that the "typename ...T" is a template parameter declaration that just appears in a somewhat unusal place.)

As a more general example:

auto foo(std::pair<typename T, typename ...U> ...pairs);

would be equivalent to:

template<typename T, typename ...U>
auto foo(std::pair<T, U> ...pairs);

(That is, it's a function that takes a sequence of pairs, where the 'first' of all pairs is the same but the 'second' can vary.)
Reply all
Reply to author
Forward
0 new messages