Conditionally compiled for_each with constexpr
authorAaryaman Sagar <aary@instagram.com>
Wed, 30 Aug 2017 21:36:25 +0000 (14:36 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 30 Aug 2017 21:58:57 +0000 (14:58 -0700)
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
folly/Foreach.h

index bdc0bb121e0a0e2645303e4d25bc28570e7b0192..c037758f5864a861abae562d440ad0f7fef92184 100644 (file)
@@ -22,6 +22,7 @@
 #include <type_traits>
 #include <utility>
 
+#include <folly/Portability.h>
 #include <folly/Traits.h>
 
 namespace folly {
@@ -378,14 +379,14 @@ struct FetchImpl<S, EnableIfRange<S>> {
 } // namespace for_each_detail
 
 template <typename Sequence, typename Func>
-constexpr Func for_each(Sequence&& range, Func func) {
+FOLLY_CPP14_CONSTEXPR Func for_each(Sequence&& range, Func func) {
   for_each_detail::ForEachImpl<typename std::decay<Sequence>::type>::impl(
       std::forward<Sequence>(range), func);
   return func;
 }
 
 template <typename Sequence, typename Index>
-constexpr decltype(auto) fetch(Sequence&& sequence, Index&& index) {
+FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index) {
   return for_each_detail::FetchImpl<Sequence>::impl(
       std::forward<Sequence>(sequence), std::forward<Index>(index));
 }
index 82c07a8203158e9901d84dc43c809f406c0921bf..34d074f10bb9631401ddbc7d888a6154d5c92eaa 100644 (file)
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include <folly/Portability.h>
 #include <folly/Preprocessor.h>
 
 #include <type_traits>
@@ -79,7 +80,7 @@ namespace folly {
  *  });
  */
 template <typename Range, typename Func>
-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 <typename Sequence, typename Index>
-constexpr decltype(auto) fetch(Sequence&& sequence, Index&& index);
+FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index);
 
 } // namespace folly