/// Create - Create a StringMapEntry with normal malloc/free.
template<typename InitType>
- static StringMapEntry *Create(StringRef Key, InitType InitVal) {
+ static StringMapEntry *Create(StringRef Key, InitType &&InitVal) {
MallocAllocator A;
- return Create(Key, A, std::move(InitVal));
+ return Create(Key, A, std::forward<InitType>(InitVal));
}
static StringMapEntry *Create(StringRef Key) {
/// exists, return it. Otherwise, default construct a value, insert it, and
/// return.
template <typename InitTy>
- MapEntryTy &GetOrCreateValue(StringRef Key, InitTy Val) {
- return *insert(std::make_pair(Key, std::move(Val))).first;
+ MapEntryTy &GetOrCreateValue(StringRef Key, InitTy &&Val) {
+ return *insert(std::pair<StringRef, ValueTy>(
+ Key, std::forward<InitTy>(Val))).first;
}
MapEntryTy &GetOrCreateValue(StringRef Key) {
ASSERT_EQ(iter->second.i, 123);
}
+struct Immovable {
+ Immovable() {}
+ Immovable(Immovable&&) LLVM_DELETED_FUNCTION; // will disable the other special members
+};
+
struct MoveOnly {
int i;
MoveOnly(int i) : i(i) {}
+ MoveOnly(const Immovable&) : i(0) {}
MoveOnly(MoveOnly &&RHS) : i(RHS.i) {}
MoveOnly &operator=(MoveOnly &&RHS) {
i = RHS.i;
MoveOnly &operator=(const MoveOnly &) LLVM_DELETED_FUNCTION;
};
-TEST_F(StringMapTest, MoveOnlyKey) {
+TEST_F(StringMapTest, MoveOnly) {
StringMap<MoveOnly> t;
t.GetOrCreateValue("Test", MoveOnly(42));
StringRef Key = "Test";
->Destroy();
}
+TEST_F(StringMapTest, CtorArg) {
+ StringMap<MoveOnly> t;
+ t.GetOrCreateValue("Test", Immovable());
+ StringRef Key = "Test";
+ StringMapEntry<MoveOnly>::Create(Key, Immovable())
+ ->Destroy();
+}
+
TEST_F(StringMapTest, MoveConstruct) {
StringMap<int> A;
A.GetOrCreateValue("x", 42);