this post was submitted on 03 Sep 2023
6 points (87.5% liked)
C++
1783 readers
1 users here now
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Your comment doesn't seem to be right at all. I mean, to start off by design
std::unique_ptr
disallows copying, andstd::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. Usingstd::unique_ptr
with a pimpl is already well established, and covered in books like Effective Modern C++, but so is the performance penalty involved.