Why is auto not allowed as an argument to a function?

From this question , it is clear that autoit cannot be used as an argument to a function. My question is why the return type is resolved as auto, but the function arguments are not?

auto function(auto data)
{
    //DOES something
}

Since there are many advantages that come autowith C ++ 1z , why not do it?

+4
source share
2 answers

This syntax was proposed in TS concepts that did not turn it into C ++ 17 for various reasons .

, , , Concepts (, ++ 20), , . " ",

TS . , , (, , ).

, :

= >

void f(auto a) {}
template<typename T> void g(auto a) {}

template<...> void f(auto a) {}
template<typename T, ...> void g(auto a) {}

... sigil , .

So Tl; dr: , , ++ 17, , , , - . , , template.

+10

, , ....

auto " ", , . , auto

auto function(auto data) {
    //...
    return x;
}

. , . , auto , , function. , function. x, auto function , .

+5

Source: https://habr.com/ru/post/1683518/


All Articles