TEST_F(StringMapTest, MoveOnlyKey) { StringMap<MoveOnly> t; t.GetOrCreateValue("Test", MoveOnly(42)); StringRef Key = "Test"; StringMapEntry<MoveOnly>::Create(Key.begin(), Key.end(), MoveOnly(42)) ->Destroy(); }
TEST_F(StringMapTest, NonDefaultConstructable) { StringMap<StringMapTestStruct> t; t.GetOrCreateValue("Test", StringMapTestStruct(123)); StringMap<StringMapTestStruct>::iterator iter = t.find("Test"); ASSERT_NE(iter, t.end()); ASSERT_EQ(iter->second.i, 123); }
TEST_F(StringMapTest, MoveConstruct) { StringMap<int> A; A.GetOrCreateValue("x", 42); StringMap<int> B = std::move(A); ASSERT_EQ(A.size(), 0u); ASSERT_EQ(B.size(), 1u); ASSERT_EQ(B["x"], 42); ASSERT_EQ(B.count("y"), 0u); }
/// GetOptionInfo - Scan the list of registered options, turning them into data /// structures that are easier to handle. static void GetOptionInfo(SmallVectorImpl<Option*> &PositionalOpts, SmallVectorImpl<Option*> &SinkOpts, StringMap<Option*> &OptionsMap) { SmallVector<const char*, 16> OptionNames; Option *CAOpt = 0; // The ConsumeAfter option if it exists. for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) { // If this option wants to handle multiple option names, get the full set. // This handles enum options like "-O1 -O2" etc. O->getExtraOptionNames(OptionNames); if (O->ArgStr[0]) OptionNames.push_back(O->ArgStr); // Handle named options. for (size_t i = 0, e = OptionNames.size(); i != e; ++i) { // Add argument to the argument map! if (OptionsMap.GetOrCreateValue(OptionNames[i], O).second != O) { errs() << ProgramName << ": CommandLine Error: Argument '" << OptionNames[i] << "' defined more than once!\n"; } } OptionNames.clear(); // Remember information about positional options. if (O->getFormattingFlag() == cl::Positional) PositionalOpts.push_back(O); else if (O->getMiscFlags() & cl::Sink) // Remember sink options SinkOpts.push_back(O); else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) { if (CAOpt) O->error("Cannot specify more than one option with cl::ConsumeAfter!"); CAOpt = O; } } if (CAOpt) PositionalOpts.push_back(CAOpt); // Make sure that they are in order of registration not backwards. std::reverse(PositionalOpts.begin(), PositionalOpts.end()); }
TEST_F(StringMapTest, MoveDtor) { int InstanceCount = 0; StringMap<Countable> A; A.GetOrCreateValue("x", Countable(42, InstanceCount)); ASSERT_EQ(InstanceCount, 1); auto I = A.find("x"); ASSERT_NE(I, A.end()); ASSERT_EQ(I->second.Number, 42); StringMap<Countable> B; B = std::move(A); ASSERT_EQ(InstanceCount, 1); ASSERT_TRUE(A.empty()); I = B.find("x"); ASSERT_NE(I, B.end()); ASSERT_EQ(I->second.Number, 42); B = StringMap<Countable>(); ASSERT_EQ(InstanceCount, 0); ASSERT_TRUE(B.empty()); }