this post was submitted on 03 Sep 2023
6 points (87.5% liked)

C++

1755 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 year ago (1 children)

This presentation from CPP-On-Sea 2022 is relavent https://youtube.com/watch?v=sjLRX4WMvlU Two classes for managing pimpl

[–] lysdexic 1 points 1 year ago (1 children)

It seems that neither std::indirect_value nor std::polymorphic_value made it into C++23, thought. Is it worth it to add them as external components just to have const qualification working with std::unique_ptr?

[–] [email protected] 1 points 1 year ago

It's a while since I saw the presentation, but I think they're both header only classes. Available at https://github.com/jbcoe

[–] robinm 0 points 1 year ago (1 children)

If only std::unique_ptr and std::variant were introduced in C++ it would be possible to use the default destructor, copy and move constructor…

That article would have been useful 15 years ago, but not anymore.

[–] lysdexic 1 points 1 year ago

If only std::unique_ptr and std::variant were introduced in C++ it would be possible to use the default destructor, copy and move constructor…

Your comment doesn't seem to be right at all. I mean, to start off by design std::unique_ptr disallows copying, and std::variant is completely wrong for the job. From thereon, it seems you're commenting on a problem you didn't understood.

The problem is not how to point to the Impl instance, but to get the pimpl-ed class to support copying, moving, etc while not leaking implementation details. This article adds another constraint to the problem, which is explore ways to mitigate the performance penalty caused by dereferencing a pointer each time it's necessary to access data members. Using std::unique_ptr with a pimpl is already well established, and covered in books like Effective Modern C++, but so is the performance penalty involved.