Skip to content

Commit

Permalink
Update safe_from_reference docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danakj authored Sep 25, 2023
1 parent adc3318 commit 9289855
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sus/construct/safe_from_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ concept IsConstLvalueReference = std::is_lvalue_reference_v<T> &&
} // namespace __private

/// Returns whether a type `From` is safely constructible from a reference of
/// type `To`. This is useful for marker types which hold a reference internally
/// and are used to construct another type.
/// type `To`. If `To` is a const reference, then the types must match, as a
/// conversion would create a reference to a temporary.
///
/// If `To` is a const reference, then they types must match, as a conversion
/// would create a reference to a temporary.
/// A struct will typically not actually store a reference but may provide an
/// API of references nonetheless, and then store a pointer. When used with a
/// universal reference `From` type, this can catch the case where the incoming
/// reference will introduce a dangling reference when converted to the `To`
/// reference.
///
/// This concept only produces a useful result when `From` is a reference type
/// which may not outlive the storage of `To`, such as with a reference to a
/// temporary.
/// # Examples
/// template <std::convertible_to<i32&> U>
/// requires(SafelyConstructibleFromReference<i32%, U&&>
/// void Struct::stores_i32_ref(U&& u) {
/// ptr_ = static_cast<i32&>(&u);
/// }
template <class To, class From>
concept SafelyConstructibleFromReference =
!__private::IsConstLvalueReference<To> ||
Expand Down

0 comments on commit 9289855

Please sign in to comment.