Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow trivially move constructible types to be relocatable #1035

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions folly/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,11 @@ struct IsNothrowSwappable
/* using override */ using traits_detail_IsNothrowSwappable::IsNothrowSwappable;

template <class T>
struct IsRelocatable : std::conditional<
struct IsRelocatable : std::conditional_t<
traits_detail::has_IsRelocatable<T>::value,
traits_detail::has_true_IsRelocatable<T>,
// TODO add this line (and some tests for it) when we
// upgrade to gcc 4.7
// std::is_trivially_move_constructible<T>::value ||
is_trivially_copyable<T>>::type {};
bool_constant<std::is_trivially_move_constructible<T>
::value || is_trivially_copyable<T>::value>>{};

template <class T>
struct IsZeroInitializable
Expand Down
14 changes: 14 additions & 0 deletions folly/test/TraitsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <type_traits>
#include <utility>

#include <folly/Portability.h>
#include <folly/ScopeGuard.h>
#include <folly/portability/GTest.h>

Expand Down Expand Up @@ -98,6 +99,19 @@ TEST(Traits, unset) {
EXPECT_TRUE(IsRelocatable<F4>::value);
}

TEST(Traits, triviallyMoveConstructible) {
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wunneeded-member-function")
struct TriviallyMoveConstructible {
TriviallyMoveConstructible(const TriviallyMoveConstructible&) = delete;
JoeLoser marked this conversation as resolved.
Show resolved Hide resolved
TriviallyMoveConstructible& operator=(const TriviallyMoveConstructible&) = delete;
TriviallyMoveConstructible(TriviallyMoveConstructible&&) = default;
JoeLoser marked this conversation as resolved.
Show resolved Hide resolved
JoeLoser marked this conversation as resolved.
Show resolved Hide resolved
TriviallyMoveConstructible& operator=(TriviallyMoveConstructible&&) = delete;
};
EXPECT_TRUE(IsRelocatable<TriviallyMoveConstructible>::value);
FOLLY_POP_WARNING
}

TEST(Traits, bitAndInit) {
EXPECT_TRUE(IsZeroInitializable<int>::value);
EXPECT_FALSE(IsZeroInitializable<vector<int>>::value);
Expand Down