Boost logo

Boost Users :

Subject: Re: [Boost-users] [TypeErasure] efficiency problem
From: Mikhail Strelnikov (mikhail.strelnikov_at_[hidden])
Date: 2017-03-24 01:02:51


I had to change the declaration of my any to:

using any = boost::type_erasure::any<mpl::vector<constructible<_self(_self&&)>,
assignable<_self, _self&&>, destructible<_self>, typeid_<>, relaxed>
>;

And then I've tried your patch, it works, thanks.

But it solves only half of the problem - there is still memory
allocation happening every time type_erasure::any is move-constructed
or move-assigned (again, there are no extra memory allocations in this
case when Boost.Any is used).

2017-03-23 15:10 GMT+03:00 Deniz Bahadir via Boost-users
<boost-users_at_[hidden]>:
> 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 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