Iros
 
Loading...
Searching...
No Matches
enable_borrowed_container.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/meta/core.h"
5#include "di/meta/language.h"
7
8namespace di::container {
9constexpr inline struct EnableBorrowedContainer {
10 // This is a helper to prevent the construction of views that would produce dangling references.
11 // As such, only rvalue references which reference explicitly borrowable type are allowed through.
12 // In particular, containers which "own" their data, like di::Vector and di::String, are not borrowable.
13 // However, di::Span and di::StringView are.
14 template<typename T>
15 constexpr auto operator()(types::InPlaceType<T>) const {
16 if constexpr (concepts::LValueReference<T>) {
17 return true;
18 } else if constexpr (concepts::TagInvocableTo<EnableBorrowedContainer, bool,
21 } else {
22 return false;
23 }
24 }
26}
Definition language.h:30
Definition tag_invoke.h:45
Definition sequence.h:12
constexpr struct di::container::EnableBorrowedContainer enable_borrowed_container
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
RemoveCV< RemoveReference< T > > RemoveCVRef
Definition core.h:74
constexpr auto in_place_type
Definition in_place_type.h:12
Definition enable_borrowed_container.h:9
constexpr auto operator()(types::InPlaceType< T >) const
Definition enable_borrowed_container.h:15
Definition in_place_type.h:5