return static_cast<T&&>(x);
}
};
-}
+
+namespace moveonly_ { // Protection from unintended ADL.
+
+/**
+ * Disallow copy but not move in derived types. This is essentially
+ * boost::noncopyable (the implementation is almost identical) but it
+ * doesn't delete move constructor and move assignment.
+ */
+class MoveOnly {
+ protected:
+ constexpr MoveOnly() = default;
+ ~MoveOnly() = default;
+
+ MoveOnly(MoveOnly&&) = default;
+ MoveOnly& operator=(MoveOnly&&) = default;
+ MoveOnly(const MoveOnly&) = delete;
+ MoveOnly& operator=(const MoveOnly&) = delete;
+};
+
+} // namespace moveonly_
+
+using MoveOnly = moveonly_::MoveOnly;
+
+} // namespace folly
* limitations under the License.
*/
-#include <folly/Utility.h>
+#include <type_traits>
+#include <folly/Utility.h>
#include <folly/portability/GTest.h>
namespace {
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");
+}