From: Yedidya Feldblum <yfeldblum@fb.com> Date: Sun, 2 Jul 2017 17:22:27 +0000 (-0700) Subject: Disambiguate the various in_place overloads, following C++17 X-Git-Tag: v2017.07.03.00~5 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=10fb4bb82bcd795e1ce2bc5a342e07617116c797;p=folly.git 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 --- diff --git a/folly/ExceptionWrapper-inl.h b/folly/ExceptionWrapper-inl.h index c1e83785..eca49ba6 100644 --- a/folly/ExceptionWrapper-inl.h +++ b/folly/ExceptionWrapper-inl.h @@ -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)...} { } diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 3a2ff717..8016168e 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -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)...}; } /** diff --git a/folly/Traits.h b/folly/Traits.h index 01222add..de720a4e 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -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 {}; }