Commit 10fb4bb8 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Disambiguate the various in_place overloads, following C++17

Summary:
[Folly] Disambiguate the various `in_place` overloads, following C++17.

Forwarding `folly::in_place` is ambiguous because there are multiple overloads and we depend on deduction to choose the correct overload. For example:

```lang=c++
enum struct Err {};
Expected<Expected<int, Err>, Err> val(in_place, in_place, 3); // fails to compile
```

So we must disambiguate the three overloads: the default, the typed, and the indexed.

C++17 defines `std::in_place`, `std::in_place_type<typename>`, and `std::in_place_index<std::size_t>`. Let us mimic that exactly, so that it becomes trivial to swap out our implementations for the standard implementations once we jump to C++17.

Reviewed By: Orvid

Differential Revision: D5362339

fbshipit-source-id: d4012b01796390e74d8c14cdf68af70102608039
parent edf661e6
......@@ -287,7 +287,7 @@ inline exception_wrapper::exception_wrapper(OnHeapTag, in_place_type_t<Ex>, As&&
template <class Ex, typename... As>
inline exception_wrapper::exception_wrapper(InSituTag, in_place_type_t<Ex>, As&&... as)
: buff_{in_place<Ex>, std::forward<As>(as)...},
: buff_{in_place_type<Ex>, std::forward<As>(as)...},
vptr_(&InPlace<Ex>::ops_) {}
inline exception_wrapper::exception_wrapper(exception_wrapper&& that) noexcept
......@@ -347,7 +347,7 @@ template <
inline exception_wrapper::exception_wrapper(Ex&& ex)
: exception_wrapper{
PlacementOf<Ex_>{},
in_place<Ex_>,
in_place_type<Ex_>,
exception_wrapper_detail::dont_slice(std::forward<Ex>(ex))} {
}
......@@ -359,7 +359,7 @@ template <
inline exception_wrapper::exception_wrapper(in_place_t, Ex&& ex)
: exception_wrapper{
PlacementOf<Ex_>{},
in_place<Ex_>,
in_place_type<Ex_>,
exception_wrapper_detail::dont_slice(std::forward<Ex>(ex))} {
}
......@@ -371,7 +371,7 @@ template <
inline exception_wrapper::exception_wrapper(in_place_type_t<Ex>, As&&... as)
: exception_wrapper{
PlacementOf<Ex>{},
in_place<Ex>,
in_place_type<Ex>,
std::forward<As>(as)...} {
}
......
......@@ -604,7 +604,7 @@ constexpr exception_wrapper::VTable exception_wrapper::InPlace<Ex>::ops_;
*/
template <class Ex, typename... As>
exception_wrapper make_exception_wrapper(As&&... as) {
return exception_wrapper{in_place<Ex>, std::forward<As>(as)...};
return exception_wrapper{in_place_type<Ex>, std::forward<As>(as)...};
}
/**
......
......@@ -636,13 +636,13 @@ inline traits_detail::InPlaceTag in_place(traits_detail::InPlaceTag = {}) {
}
template <class T>
inline traits_detail::InPlaceTypeTag<T> in_place(
inline traits_detail::InPlaceTypeTag<T> in_place_type(
traits_detail::InPlaceTypeTag<T> = {}) {
return {};
}
template <std::size_t I>
inline traits_detail::InPlaceIndexTag<I> in_place(
inline traits_detail::InPlaceIndexTag<I> in_place_index(
traits_detail::InPlaceIndexTag<I> = {}) {
return {};
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment