Menu

Failse positive accessMoved

2022-01-17
2022-01-17
  • Anton Davidenko

    Anton Davidenko - 2022-01-17

    example:

        struct S
        {
            int i = 0;
            bool operator < (const S& rhs) const
            {
                return i < rhs.i;
            }
        } s;
        std::set<S> set1, set2;
        auto [it, inserted] = set1.emplace(std::move(s));
        if (!inserted)
        {
            set2.insert(std::move(s));
        }
    
     
  • CHR

    CHR - 2022-01-17

    Not sure about this one. According to https://en.cppreference.com/w/cpp/container/set/emplace, an element might be constructed (move-constructed in this case) even if no insertion takes place.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.