Commit d9ae16d1 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

tweak in-place backport

Summary:
Use inline variables to avoid the function-pointer trick.

Use explicit default constructors per the types in the standard.

Import the names from the standard in C++17.

This allows declaring a function with tags from one namespace and calling the function with tags from the other namespace in C++17.

Reviewed By: vitaut

Differential Revision: D32588945

fbshipit-source-id: 0ece26ebf7f9f6acf9abb8b008327f06f84091f2
parent e19669d3
...@@ -119,29 +119,42 @@ constexpr like_t<Src, Dst>&& forward_like(Dst&& dst) noexcept { ...@@ -119,29 +119,42 @@ constexpr like_t<Src, Dst>&& forward_like(Dst&& dst) noexcept {
* std::in_place_index * std::in_place_index
*/ */
struct in_place_tag {}; #if FOLLY_CPLUSPLUS >= 201703L
template <class>
struct in_place_type_tag {};
template <std::size_t>
struct in_place_index_tag {};
using in_place_t = in_place_tag (&)(in_place_tag); using std::in_place_t;
template <class T>
using in_place_type_t = in_place_type_tag<T> (&)(in_place_type_tag<T>);
template <std::size_t I>
using in_place_index_t = in_place_index_tag<I> (&)(in_place_index_tag<I>);
inline in_place_tag in_place(in_place_tag = {}) { using std::in_place_type_t;
return {};
} using std::in_place_index_t;
using std::in_place;
using std::in_place_type;
using std::in_place_index;
#else
struct in_place_t {
explicit in_place_t() = default;
};
FOLLY_INLINE_VARIABLE constexpr in_place_t in_place{};
template <class>
struct in_place_type_t {
explicit in_place_type_t() = default;
};
template <class T> template <class T>
inline in_place_type_tag<T> in_place_type(in_place_type_tag<T> = {}) { FOLLY_INLINE_VARIABLE constexpr in_place_type_t<T> in_place_type{};
return {};
} template <std::size_t>
struct in_place_index_t {
explicit in_place_index_t() = default;
};
template <std::size_t I> template <std::size_t I>
inline in_place_index_tag<I> in_place_index(in_place_index_tag<I> = {}) { FOLLY_INLINE_VARIABLE constexpr in_place_index_t<I> in_place_index{};
return {};
} #endif
/** /**
* Initializer lists are a powerful compile time syntax introduced in C++11 * Initializer lists are a powerful compile time syntax introduced in C++11
......
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