Skip to content

Commit a900c0f

Browse files
Wenbin Linmeta-codesync[bot]
authored andcommitted
Revert D88284968: Slight cleanup of find_by_ordinal
Differential Revision: D88284968 Original commit changeset: ac3a59f9418a Original Phabricator Diff: D88284968 fbshipit-source-id: 2d2da05b4aeb248481906602d9b5e71afb00f6c8
1 parent 500bc05 commit a900c0f

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

  • third-party/thrift/src/thrift/lib/cpp2/op

third-party/thrift/src/thrift/lib/cpp2/op/Get.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ using ord_result_t =
250250
decltype(std::declval<F>()(type::detail::pos_to_ordinal<I>{}));
251251

252252
template <size_t... I, typename F>
253-
constexpr ord_result_t<F> find_by_ordinal_impl(
254-
F&& f, std::index_sequence<I...>);
255-
template <typename F>
256-
constexpr bool find_by_ordinal_impl(F&&, std::index_sequence<>);
253+
ord_result_t<F> find_by_ordinal_impl(F&& f, std::index_sequence<I...>);
257254

258255
struct GetValueOrNull {
259256
template <typename T>
@@ -337,15 +334,22 @@ constexpr void for_each_ordinal(F&& f) {
337334
std::forward<F>(f), std::make_integer_sequence<size_t, num_fields<T>>{});
338335
}
339336

340-
/// Calls the given function with with ordinal<1> to ordinal<N>, returning the
341-
/// first truthy result produced.
342-
/// Returns false when called on empty structs.
343-
template <typename T, typename F>
344-
constexpr decltype(auto) find_by_ordinal(F&& f) {
337+
/// Calls the given function with with ordinal<1> to ordinal<N>, returing the
338+
/// first 'true' result produced.
339+
template <
340+
typename T,
341+
typename F,
342+
std::enable_if_t<num_fields<T> != 0>* = nullptr>
343+
decltype(auto) find_by_ordinal(F&& f) {
345344
return detail::find_by_ordinal_impl(
346345
std::forward<F>(f), std::make_integer_sequence<size_t, num_fields<T>>{});
347346
}
348347

348+
template <typename T, typename F>
349+
std::enable_if_t<num_fields<T> == 0, bool> find_by_ordinal(F&&) {
350+
return false;
351+
}
352+
349353
template <typename T, typename Id>
350354
using get_field_id = type::field_id<
351355
get_ordinal<T, Id>::value == type::Ordinal()
@@ -473,8 +477,7 @@ constexpr void for_each_ordinal_impl(F&& f, std::index_sequence<I...>) {
473477
}
474478

475479
template <size_t... I, typename F>
476-
constexpr ord_result_t<F> find_by_ordinal_impl(
477-
F&& f, std::index_sequence<I...>) {
480+
ord_result_t<F> find_by_ordinal_impl(F&& f, std::index_sequence<I...>) {
478481
auto result = ord_result_t<F>();
479482
// TODO(afuller): Use a short circuting c++17 folding expression.
480483
for_each_ordinal_impl(
@@ -487,10 +490,6 @@ constexpr ord_result_t<F> find_by_ordinal_impl(
487490
std::index_sequence<I...>{});
488491
return result;
489492
}
490-
template <typename F>
491-
constexpr bool find_by_ordinal_impl(F&&, std::index_sequence<>) {
492-
return false;
493-
}
494493

495494
template <typename Id, typename T>
496495
struct Get {

0 commit comments

Comments
 (0)