C++ Logo


Advanced search

Re: Partial type definition

From: Henry Miller <hank_at_[hidden]>
Date: Thu, 26 Aug 2021 14:03:58 -0500
  Henry Miller
On Thu, Aug 26, 2021, at 13:49, Jason McKesson via Std-Proposals wrote:
> On Thu, Aug 26, 2021 at 2:24 PM Valery Osheter via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > In case of PIMPL you have to wrap each interface method. My proposal requires only to declare methods. Does it not make the forward method declaration attractive to people?
> > It does not allow to create the instance of the class as PIMPL does,
> That's my point. Being able to create an instance of the PIMPL class
> is kind of important for many existing uses of PIMPL.
Some of them, but in general I'm looking for a solution for users of the class, there are a lot of times where I want to use a class. I'm fine with creation and destruction  needing the full definition. This lets me do a lot more than what a simple forward declaration would. 
If I don't like the above restriction I can always write a static create function.
Though I'm suspecting this might be a time where someone needs to write a clang extension just to verify it is as great as we think it should be.
> > but except that it allows to write all tests of the class and to do it directly without a PIMPL intermediary.
> How does this affect the point I just made?
> Also, it's not clear to me why it matters if your tests can be written
> against forward declarations. Even if the person writing the tests and
> the person implementing the type are two different people, they can be
> working off of the same header file, right? So how does being able to
> forward declare members help with writing tests?
> > Note that the implementation class must be defined at the place PIMPL creates its instance. This is the same as in my method, the object creation requires the class to be defined anyway.
> No, it does not. The implementation class needs to be *declared*
> there, but it need not be *defined* there:
> ```
> class impl; //declaration, not definition.
> class iface
> {
> private:
>   std::unique_ptr<impl> impl_;
> public:
>   iface(params); //No definition.
>   ~iface(); //No definition.
>   iface(iface const&); //No definition.
> //etc
> };
> ```
> As long as you don't *define* the member functions in the header
> (which your idea doesn't support anyway), this code is fine.
> -- 
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2021-08-26 14:04:23