Date: Tue, 29 Apr 2025 17:19:57 -0700
On Tuesday, 29 April 2025 09:27:10 Pacific Daylight Time Yexuan Xiao via Std-
Proposals wrote:
> In other words, a trait that std::string_view, winrt::hstring, and QString
> satisfy—but std::string does not, would allow generic code to store such
> types by value without wrapping them in std::unique_ptr or other wrappers.
> It can be implemented as follows and allows users to specialize:
Can you define more concretely what "cheap" here is?
Is it that the copy constructor is noexcept, thus effectively is not allowed to
allocate memory?
Is it that it is of fixed runtime? Do note that incrementing reference counters
is not loop-free in some architectures.
Does it have to be O(1)? Does a single std::array object count as O(1)?
Because I'm not entirely sure what you're trying to do, when you mentioned
triviality in the same breath. QString is fast to copy because it's COW, but
it's not trivially copyable. It is trivially relocatable though.
Proposals wrote:
> In other words, a trait that std::string_view, winrt::hstring, and QString
> satisfy—but std::string does not, would allow generic code to store such
> types by value without wrapping them in std::unique_ptr or other wrappers.
> It can be implemented as follows and allows users to specialize:
Can you define more concretely what "cheap" here is?
Is it that the copy constructor is noexcept, thus effectively is not allowed to
allocate memory?
Is it that it is of fixed runtime? Do note that incrementing reference counters
is not loop-free in some architectures.
Does it have to be O(1)? Does a single std::array object count as O(1)?
Because I'm not entirely sure what you're trying to do, when you mentioned
triviality in the same breath. QString is fast to copy because it's COW, but
it's not trivially copyable. It is trivially relocatable though.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering
Received on 2025-04-30 00:20:00