P1168R0
Mike Spertus, Symantec
mike_spertus@symantec.com
2018-10-08
Audience: Evolution Working Group
C++17 + P1141R1 | Proposed | ||
---|---|---|---|
|
|
While C++17 Class Template Argument Deduction can often be used in such situations (e.g., if the pmr::vector above had been an ordinary vector), the example above was crafted to illustrate the value of potential improvements to Class Template Argument Deduction, such as return type deduction below, and aggregate and type alias deduction. Such basic "filling of holes" would help a lot as illustrated in the example, and is covered in P1021R1 and P1167R0. The remainder of this paper focuses specifically on aligning Class Template Argument Deduction Inferencing with Constrained Type Inferencing.
Let us look at some particular cases.
it should be possible to omit the auto to get
Constraint auto f1();
As justification, P1141R1 specifically refers to Class Template Argument Deduction allowing
Constraint f1();
By the same reasoning, it makes sense for us to be consistent in the other direction and allow
std::tuple x = foo();
Otherwise, the programmer has to remember a bunch of special-cased rules as to which kinds of deduced declarations can accept an auto or not.
std::tuple auto x = foo();
one should also be able to say
Constraint auto f1();
to make explicit that constrained type deduction is taking place (In this context, we are using the phrase “constrained type deduction” to refer to the fact that the deduced type is given more specifically than just a lone auto). The example given at the top of this paper of f returning
tuple auto f1();
instead of
pair auto
illustrates just how much this can simplify code.
pair<decltype(c), pmr::vector<
typename
decltype(c.ctrl_pts)::value_type>>
Notes:
tuple t = {1,
"foo"
};
tuple auto g() {
return
{1,
"foo"
}; }
one should also be able to indicate that a declaration has its arguments deduced by
void
f1(Constraint auto x);
This is not only more consistent, but we think it can have a huge impact on facilitating terse notation as now almost any function template could be written using natural function notation as shown by the following example (which also demonstrates the value of partially-specialized template argument lists as proposed in P1021R0) extension
void
f1(tuple auto x);
C++17 + P1141R1 | Proposed | ||
---|---|---|---|
|
|
tuple<Copyable> t(1);