Add conversion constructors for Future
authorSubodh Iyengar <subodh@fb.com>
Tue, 1 Mar 2016 03:38:32 +0000 (19:38 -0800)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Tue, 1 Mar 2016 03:50:33 +0000 (19:50 -0800)
commit692cc4b1f5872a9ad802ba2af8eadee24f540480
tree8a8d4705aca4dead5490e6fe189832fad28df4ec
parent8edf04da5cc42f5d417af9c4e489e9769f5d7927
Add conversion constructors for Future

Summary:previously we were not able to do

Future<Base> f = makeFuture<Derived>();

This is because Future did not declare a conversion
constructor.

Adding a proper conversion ctor for Future is very
tricky because of the way Core is managed under the hood.
Core is not movable, and cannot be moved otherwise we
would have to retain pointers to the Future and Promises which
pointed to a particular core. This would be inefficient.

Instead we compromise and allow a very small subset of conversions
from objects whose templated types are convertible and also the
sizes of their Cores are also the same. As a result, we can
convert between types like unique_ptrs however not always between
full objects.

Reviewed By: jsedgwick

Differential Revision: D2943775

fb-gh-sync-id: 7c2388f2fb49d789c80ae2477814e960a099771b
shipit-source-id: 7c2388f2fb49d789c80ae2477814e960a099771b
folly/futures/Future-inl.h
folly/futures/Future.h
folly/futures/detail/Core.h
folly/futures/test/ConversionTest.cpp [new file with mode: 0644]
folly/test/Makefile.am