/**
* Construct a FunctionRef from a reference to a callable object.
*/
- template <typename Fun>
+ template <
+ typename Fun,
+ typename std::enable_if<
+ !std::is_same<FunctionRef, typename std::decay<Fun>::type>::value,
+ int>::type = 0>
/* implicit */ FunctionRef(Fun&& fun) noexcept {
using ReferencedType = typename std::remove_reference<Fun>::type;
using folly::Function;
using folly::FunctionRef;
+TEST(FunctionRef, Traits) {
+ static_assert(std::is_literal_type<FunctionRef<int(int)>>::value, "");
+// Some earlier versions of libstdc++ lack these traits. Frustrating that
+// the value of __GLIBCXX__ doesn't increase with version, but rather reflects
+// release date, so some larger values of __GLIBCXX__ lack the traits while
+// some smaller values have them. Can't figure out how to reliably test for the
+// presence or absence of the traits. :-(
+#if !defined(__GLIBCXX__) || __GNUC__ >= 5
+ static_assert(
+ std::is_trivially_copy_constructible<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_trivially_move_constructible<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_trivially_constructible<
+ FunctionRef<int(int)>,
+ FunctionRef<int(int)>&>::value,
+ "");
+ static_assert(
+ std::is_trivially_copy_assignable<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_trivially_move_assignable<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_trivially_assignable<
+ FunctionRef<int(int)>,
+ FunctionRef<int(int)>&>::value,
+ "");
+#endif
+ static_assert(
+ std::is_nothrow_copy_constructible<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_nothrow_move_constructible<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_nothrow_constructible<
+ FunctionRef<int(int)>,
+ FunctionRef<int(int)>&>::value,
+ "");
+ static_assert(
+ std::is_nothrow_copy_assignable<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_nothrow_move_assignable<FunctionRef<int(int)>>::value, "");
+ static_assert(
+ std::is_nothrow_assignable<
+ FunctionRef<int(int)>,
+ FunctionRef<int(int)>&>::value,
+ "");
+}
+
TEST(FunctionRef, Simple) {
int x = 1000;
auto lambda = [&x](int v) { return x += v; };