MoveOnly utility
[folly.git] / folly / test / UtilityTest.cpp
index 9b77e170099aacf96ec1b887f33eec0731f6d4ba..5507b96f8855c193f08667b3a89b0c62bb2491cb 100644 (file)
@@ -14,8 +14,9 @@
  * limitations under the License.
  */
 
  * limitations under the License.
  */
 
-#include <folly/Utility.h>
+#include <type_traits>
 
 
+#include <folly/Utility.h>
 #include <folly/portability/GTest.h>
 
 namespace {
 #include <folly/portability/GTest.h>
 
 namespace {
@@ -88,3 +89,24 @@ TEST(FollyIntegerSequence, core) {
   static_assert(seq3.size() == 3, "");
   EXPECT_EQ(3, seq3.size());
 }
   static_assert(seq3.size() == 3, "");
   EXPECT_EQ(3, seq3.size());
 }
+
+TEST_F(UtilityTest, MoveOnly) {
+  class FooBar : folly::MoveOnly {
+    int a;
+  };
+
+  static_assert(
+      !std::is_copy_constructible<FooBar>::value,
+      "Should not be copy constructible");
+
+  // Test that move actually works.
+  FooBar foobar;
+  FooBar foobar2(std::move(foobar));
+  (void)foobar2;
+
+  // Test that inheriting from MoveOnly doesn't prevent the move
+  // constructor from being noexcept.
+  static_assert(
+      std::is_nothrow_move_constructible<FooBar>::value,
+      "Should have noexcept move constructor");
+}