Boost logo

Boost Users :

Subject: Re: [Boost-users] [TypeErasure] efficiency problem
From: Deniz Bahadir (dbahadir_at_[hidden])
Date: 2017-03-23 12:10:10


Am 23.03.2017 um 06:55 schrieb Mikhail Strelnikov via Boost-users:
> Hello!
>
> In following code TypeErasure creates two copies of s, while Boost.Any
> creates no copies at all.
>
> any x{ s{} };
> any y{ std::move(x) };
> any z;
> z = std::move(y);
>
> There is move constructor for type_erasure::any, but it does allocate
> memory and calls copy constructor for s. Why?

I am not really sure, but I investigated this over a year ago and I
think the problem was either that no real move-constructor was
implemented or the wrong constructor overload was taken. (I think,
taking the wrong overload happened at least in some of my personal
test-cases back then. The constructor with the "universal reference" [1]
very often better matched the inputs than some of the overloads.)

> And why there is no move assignment operator in type_erasure::any?

A pull-request to Boost.TypeErasure exists [2] which adds support for
move-assignment. (I wrote this about a year ago and we have been using
it successfully in production-code at our company for over half a year now.)
However, this pull-request seems to have been overlooked by the author
of Boost.TypeErasure.

If you do not mind using a patched version of Boost.TypeErasure you
could apply this pull-request to your local version of Boost and use that.
Of course, I would prefer if this pull-request (or some other
pull-request adding move-assignment support) would make it into the
official version of Boost.TypeErasure.

Hope that helps,
Deniz

[1] https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
[2] https://github.com/boostorg/type_erasure/pull/12

>
> Thanks.
>
> Full source: https://wandbox.org/permlink/iHs5a0bjzXsBtpwC
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net