Attached are my latest experimental polymorphic lambda patches against the latest lambda branch. Template parameters implied by auto in the lambda's call parameter list no longer lose qualifiers. The following examples produce equivalent functions:
1. [] (auto x, auto& y, auto const& z) { return x + y + z; }
2. [] <typename X, typename Y, typename Z> (X x, Y& y, Z const& z) {
return x + y + z; }
3. [] <typename Y> (auto x, Y& y, auto const& z) { return x + y + z; }
Note that using an explicit template parameter is only really useful if you
wish to either a) ensure consistency among
a number of call parameters, b) use a non-type template parameter or c) specify
a call parameter type constraint (or
other complex parameter type).
I have flattened the latest auto-template-inference changes with the previous
one to remove complexity due to
re-arrangement. In particular it no longer abuses decl.c -- those changes have
currently moved into parser.c but it
is pretty clear that they have more in common with pt.c owing to a need to pull
in some local static functions from
that file. I intend to split or move parts (or most) into pt.c on my next
attempt (if I get time to make one!)
There are currently many issues:
- efficiency of template parameter list growing.
- implicit return type deduction doesn't work from
inside a template context if the lambda's return
expression involves a dependent type. Specifying
decltype explicitly in these contexts is a
workaround.
- dependent inferred return type needs to be
deferred and decayed. This may go some way (all
the way?) to solving the previous point.
- location of implementation.
- only a few use-cases have been considered.
Adam
Summary:
Subject: [PATCH] First pass polymorphic lambda support.
This commit adds experimental support for an optional template-parameter-list
in angle-brackets at the start of a
lambda-parameter-declaration.
---
Subject: [PATCH] Restored decltype in lambda return type deduction for when
expr is dependent.
---
Subject: [PATCH] Second version of typename inference from auto parameters in
lambda call operator.
Still quite hacky -- though better than previous. No longer loses
qualifiers on replaced auto parameters so is functionally closer to
what's really needed.
- This is just a behavioural proof to find out how things work.
- Need to shuffle some stuff into pt.c and do away with code dup.
- Not sure how to free tree_vec's and tidy up the counts and sizes
(looks like they're only intended to grow.)
- Added `type_decays_to (non_reference (finish_decltype_type' as
suggested by Jason. Currently doesn't remove cv-quals from
non-class types though. Need to treat implicit return type
differently for dependent types -- should defer and mark that it
needs to be computed later.
---
0001-First-pass-polymorphic-lambda-support.patch
Description: Binary data
0002-Restored-decltype-in-lambda-return-type-deduction-fo.patch
Description: Binary data
0003-Second-version-of-typename-inference-from-auto-param.patch
Description: Binary data
