You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a908bf0
Browse filesBrowse the repository at this point in the historyBrowse files
Spell make_unique for array as the standard does (#574)
```diff
- template <typename T1> std::unique_ptr<T1[]> f1(std::size_t n) {
- return std::make_unique<T1[]>(n);
+ template <typename T1> auto f1(std::size_t a0) {
+ return std::make_unique<T1>(a0);
}
```
There is no `std::make_unique<T1[]>(n)` in the standard, only
`std::make_unique<T1>(a0)`. Spell the rules as the standard does.
---
For that, I added a new marker trait called CppArray that unwraps the
element so that the rule for array make_unique can be written as:
```
unsafe fn f1<T1: CppArray<T2>, T2: Default>(a0: usize) -> Option<Box<[T2]>> {
Some((0..a0).map(|_| <T2>::default()).collect::<Box<[_]>>())
}
```
CppArray uses the same infrastructure as CppFrom and CppIterator.
---
I also had to add a fallback for matching the template arguments. In the
new spelling of make_unique, T1 becomes undeducible because it does not
appear in the arguments or returns type of the rule. So we deduce T1
from the callee of the return expr.
0 commit comments