Disambiguate the various in_place overloads, following C++17
authorYedidya Feldblum <yfeldblum@fb.com>
Sun, 2 Jul 2017 17:22:27 +0000 (10:22 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 2 Jul 2017 17:40:21 +0000 (10:40 -0700)
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

folly/ExceptionWrapper-inl.h
folly/ExceptionWrapper.h
folly/Traits.h

index c1e8378534dc421095986f0a100908c603d417a5..eca49ba6efcd3e6acf7532ee3ac885d44f3be10c 100644 (file)
@@ -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)...} {
 }
 
index 3a2ff7179ca2ac5239b09fb9c0a36091ed935be9..8016168e2bb3789fe9c04099fd014ccb396a3ac2 100644 (file)
@@ -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)...};
 }
 
 /**
index 01222addfd0ff454fe49eecf3ae2051d9b1274bd..de720a4eb6a4eaf11e22f3022ef747c9ecdb81a5 100644 (file)
@@ -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 {};
 }