From f45b792f2f589050f74a02d5edb7ddb8be5703b9 Mon Sep 17 00:00:00 2001 From: Aaryaman Sagar Date: Wed, 30 Aug 2017 14:36:25 -0700 Subject: [PATCH] Conditionally compiled for_each with constexpr Summary: Code was breaking in versions of C++ where constexpr functions are required to have one line bodies Reviewed By: yfeldblum, mzlee Differential Revision: D5739062 fbshipit-source-id: 6c509f1daf77751d33ce9c173a0d7f1d3bd2a006 --- folly/Foreach-inl.h | 5 +++-- folly/Foreach.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/folly/Foreach-inl.h b/folly/Foreach-inl.h index bdc0bb12..c037758f 100644 --- a/folly/Foreach-inl.h +++ b/folly/Foreach-inl.h @@ -22,6 +22,7 @@ #include #include +#include #include namespace folly { @@ -378,14 +379,14 @@ struct FetchImpl> { } // namespace for_each_detail template -constexpr Func for_each(Sequence&& range, Func func) { +FOLLY_CPP14_CONSTEXPR Func for_each(Sequence&& range, Func func) { for_each_detail::ForEachImpl::type>::impl( std::forward(range), func); return func; } template -constexpr decltype(auto) fetch(Sequence&& sequence, Index&& index) { +FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index) { return for_each_detail::FetchImpl::impl( std::forward(sequence), std::forward(index)); } diff --git a/folly/Foreach.h b/folly/Foreach.h index 82c07a82..34d074f1 100644 --- a/folly/Foreach.h +++ b/folly/Foreach.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include @@ -79,7 +80,7 @@ namespace folly { * }); */ template -constexpr Func for_each(Range&& range, Func func); +FOLLY_CPP14_CONSTEXPR Func for_each(Range&& range, Func func); /** * The user should return loop_break and loop_continue if they want to iterate @@ -115,7 +116,7 @@ constexpr auto loop_continue = for_each_detail::LoopControl::CONTINUE; * (operator[]) to fetch the required element */ template -constexpr decltype(auto) fetch(Sequence&& sequence, Index&& index); +FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index); } // namespace folly -- 2.34.1