[Development] Views in APIs

Marc Mutz marc.mutz at kdab.com
Thu May 14 11:33:43 CEST 2020


On 2020-05-14 02:15, Thiago Macieira wrote:
> On quarta-feira, 13 de maio de 2020 01:41:26 PDT Иван Комиссаров wrote:
>> std::span<Product> Project::productsSpan() const & { return 
>> d->products; }
>> std::span<Product> Project::productsSpan() const && = delete;
> 
> Now implement either or both of these functions if internally you have 
> a
> QSet<Products>.

Now implement QHash<Qt::ItemRole, QByteArray> roleNames() when 
internally you have a std::pmr::unordered_map<Qt::ItemRole, 
std::pmr::string>, with all the data allocated from one 
std::pmr::monotonic_buffer_resource.

This does both ways.

And: you can also have views over associated data structures, they just 
can't have inline functions because they need to type-erase the 
container. For an extreme example, consider QAssociativeIterable.

Thanks,
Marc


More information about the Development mailing list