Expose the time remaining in HHWheelTimer::Callback
[folly.git] / folly / test / FunctionRefTest.cpp
index 621b0ad8205b519d6c8c7ab859076c7170dc4404..6ddf62ad44e1c4cf4ffa9f58c41468df6d9926f4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 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; };
@@ -137,11 +184,13 @@ TEST(FunctionRef, OverloadedFunctor) {
 TEST(FunctionRef, DefaultConstructAndAssign) {
   FunctionRef<int(int, int)> fref;
 
+  EXPECT_FALSE(fref);
   EXPECT_THROW(fref(1, 2), std::bad_function_call);
 
   int (*func)(int, int) = [](int x, int y) { return 10 * x + y; };
   fref = func;
 
+  EXPECT_TRUE(fref);
   EXPECT_EQ(42, fref(4, 2));
 }