Skip to content

Conversation

@danakj
Copy link
Collaborator

@danakj danakj commented Sep 9, 2023

The dyn() function requires a template parameter of the type erasure class DynC of concept C currently.

Whereas into() does not, since it constructs a marker type and then uses type deduction to determine what to construct.

We should in theory be able to do the same with Dyn and have it defer choosing the reference type until the operator is called, but it may be tricky to maintain const correctness.

Here's a test demo envionment in which this could be explored: https://godbolt.org/z/Y5nGe4E16

Filed #358 for this enchancement.

danakj and others added 19 commits September 10, 2023 03:22
Generalize Box<DynError>::from(Error auto) to work with any DynConcept
type erasure, with Box<DynC>::from(C auto).
The reference may be an rvalue and it may need to be used as an rvalue
in order to get the desired type from it.
This can be useful when it lives on the stack in order to extend its
lifetime.
Now that everything can be constexpr we can just max_by and min_by
in the implementation of them.
On clang 16 (but not after for some reason) the concept will not match
any type `F` that is pure virtual. This prevented FnMut from matching
against DynFnMut.

More precisely:

```
template <class T>
concept C = requires(T t) { t.foo(); }
```

This won't match a pure virtual `T` with a mutable `foo()` on clang 16.
It works on 17+ and with GCC 13 and MSVC (at least one version).

`requires(T& t)` does the right thing universally, as in:

```
template <class T>
concept C = requires(T& t) { t.foo(); }
```

Add a rule to STYLE.md and update all concepts that wrote a value type
in a rule to be reference types.
@danakj danakj changed the title DynFn Generalized type erasure of concept types with or without heap allocation Sep 10, 2023
@danakj danakj marked this pull request as ready for review September 10, 2023 21:36
These are superceded by the general concept-type-erasure mechanism
of DynConcept and the DynFn/Mut/Once type-erasure support types.
Box::with_args() will pass the args to the ctor of T to construct
it directly on the heap.
@danakj danakj merged commit 697051f into chromium:main Sep 11, 2023
@danakj danakj deleted the dynfn branch September 11, 2023 03:59
@danakj danakj mentioned this pull request Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant