C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Question regarding auto as template argument

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Mon, 22 May 2023 11:04:39 -0400
On Mon, May 22, 2023 at 10:54 AM Ville Voutilainen wrote:

> On Mon, 22 May 2023 at 17:50, Guillaume Racicot wrote:
> > If we follow concept syntax, we could also use a concept name:
> > auto f(std::vector<std::integral>) -> void {
>
> Right, so then
>
> auto f(std::vector<std::integral auto>) -> void;
> and
> auto f(std::vector<auto>) -> void;
>
> would make fair amounts of sense.
>

As Ville might already know, GCC (as an extension) supports the
concept-constrained auto syntax just as naturally as the unconstrained auto
syntax. :)
// https://godbolt.org/z/YWrxMh57b

void f(const std::vector<std::integral auto>&); // #1; note this syntax is
an extension
void f(const auto&); // #2; this syntax is standard C++20

extern std::vector<int> vi;
extern std::vector<float> vf;

int main() {
f(vi); // calls f #1
f(vf); // calls f #2
}

–Arthur

Received on 2023-05-22 15:04:52