Nicole Mazzuca
unread,Jul 12, 2017, 5:52:23 AM7/12/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to std-pr...@isocpp.org
`Concept` in return type position:
I was talking with some people on the cpplang slack about Bjarne's
latest paper on concepts in function parameter context, and I thought
of something I would find very useful. Basically:
```
Concept foo();
```
should be equivalent to
```
auto foo();
```
except that the compiler makes certain that the deduced return type
satisfies the concept Concept; this would be useful for documentation,
without committing to a specific return type, while also making
certain that the compiler actually checks all instantiations. This
would be especially useful if, eventually, C++ gets definition
checking. However, for now, it would only check each instantiation.
This is clearly incompatible with Bjarne's proposed consistent concept
types, but it works well with independent concept types, and is, I
think, a good argument for them. A real world example where they would
be useful:
```
// note: Iterable<T, U> means that U is an iterable with value_type T
template <typename T, Iterable<T> It, typename F>
auto map(It it, F f) -> Iterable<decltype(f(std::declval<T>()))> {
struct ret {
struct ret_iter {
decltype(it.begin()) begin;
F map;
// etc.
};
struct ret_iter_end {
decltype(it.end()) end;
};
It iterable;
// etc.
}
return ret(std::move(it), std::move(f));
}
```
It's unimportant that the return type of map is `map::ret`; only that
it's an iterable with value_type that's equal to the return type of
the passed functor applied to the value_type of the iterable passed
in.
- Nicole Mazzuca (ubsan)