Date: Wed, 4 Jan 2023 17:41:36 +0100
Hi,
Il 04/01/23 16:55, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> I could go a step further and make it work with user-defined classes;
> in order to get this to work there would have to be a global container
> containing elements of type pair<
> type_info*,function<void(ostream&,void*)> > -- and for this to work
> properly in multithreaded programs then either:
> (a) The container must be populated from the main thread before
> any other thread is spawned
> (b) Protect the container with a mutex
This sounds complicated and does not really sound suitable for
standardization -- which container? protected under which circumstances?
who populates it? who destroys it?
This would inevitably end up in ad-hoc client code, which sounds
possible today as you've shown (you can't just call it
operator<<(ostream, any)).
But why a repository? Can't this be achieved by extending `any` so that
not only it type-erases a ostream streaming function, if one "exists",
in addition to destruction/copy/move?
Yes, then: why stopping there, and not also having `any` store
type-erased versions of sizeof(T), alignof(T), operator==(T, T), "how to
serialize T into JSON"?
My 2 c,
Il 04/01/23 16:55, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> I could go a step further and make it work with user-defined classes;
> in order to get this to work there would have to be a global container
> containing elements of type pair<
> type_info*,function<void(ostream&,void*)> > -- and for this to work
> properly in multithreaded programs then either:
> (a) The container must be populated from the main thread before
> any other thread is spawned
> (b) Protect the container with a mutex
This sounds complicated and does not really sound suitable for
standardization -- which container? protected under which circumstances?
who populates it? who destroys it?
This would inevitably end up in ad-hoc client code, which sounds
possible today as you've shown (you can't just call it
operator<<(ostream, any)).
But why a repository? Can't this be achieved by extending `any` so that
not only it type-erases a ostream streaming function, if one "exists",
in addition to destruction/copy/move?
Yes, then: why stopping there, and not also having `any` store
type-erased versions of sizeof(T), alignof(T), operator==(T, T), "how to
serialize T into JSON"?
My 2 c,
-- Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts
Received on 2023-01-04 16:41:40