Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Web Components: Working With Shadow DOM

      July 28, 2025

      Google’s new Opal tool allows users to create mini AI apps with no coding required

      July 28, 2025

      Designing Better UX For Left-Handed People

      July 25, 2025

      This week in AI dev tools: Gemini 2.5 Flash-Lite, GitLab Duo Agent Platform beta, and more (July 25, 2025)

      July 25, 2025

      Microsoft wants you to chat with its browser now – but can you trust this Copilot?

      July 28, 2025

      I tested the Dell XPS’ successor – here are the biggest upgrades (and what’s the same)

      July 28, 2025

      I’m a Linux pro – here are my top 5 command line backup tools for desktops and servers

      July 28, 2025

      Should you buy a refurbished iPad? I tried one from Back Market and here’s my verdict

      July 28, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      elegantweb/sanitizer

      July 28, 2025
      Recent

      elegantweb/sanitizer

      July 28, 2025

      Streamlined String Encryption with Laravel’s Fluent Methods

      July 28, 2025

      Resume PHP

      July 28, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Gamers bypass UK age verification with Death Stranding — no real face or VPN required

      July 28, 2025
      Recent

      Gamers bypass UK age verification with Death Stranding — no real face or VPN required

      July 28, 2025

      New Xbox games launching this week, from July 28 through August 3 — Grounded 2 arrives on Xbox Game Pass

      July 28, 2025

      TikTok’s owner forked Microsoft’s Visual Studio Code and concerns have been raised — reports suggest it’s resource heavy and never stops ‘phoning home’

      July 28, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: An Exert Operation

    CodeSOD: An Exert Operation

    July 28, 2025

    The Standard Template Library for C++ is… interesting. A generic set of data structures and algorithms was a pretty potent idea. In practice, early implementations left a lot to be desired. Because the STL is a core part of C++ at this point, and widely used, it also means that it’s slow to change, and each change needs to go through a long approval process.

    Which is why the STL didn’t have a std::map::containsfunction until the C++20 standard. There were other options. For example, one could usestd::map::count, to count how many times a key appear. Or you could use std::map::findto search for a key. One argument against adding astd::map::containsfunction is thatstd::map::count basically does the same job and has the same performance.

    None of this stopped people from adding their own. Which brings us to Gaetan‘s submission. Absent a std::map::contains method, someone wrote a whole slew of fieldExists methods, where field is one of many possible keys they might expect in the map.

    bool DataManager::thingyExists (string name)
    {
        THINGY* l_pTHINGY = (*m_pTHINGY)[name];
        if(l_pTHINGY == NULL)
        {
            m_pTHINGY->erase(name);
            return false;
        }
            else
        {
            return true;
        }
        return false;
    }
    

    I’ve head of upsert operations- an update and insert as the same operation, but this is the first exert- an existence check and an insert in the same operation.

    “thingy” here is anonymization. The DataManager contained several of these methods, which did the same thing, but checked a different member variable. Other classes, similar to DataManager had their own implementations. In truth, the original developer did a lot of “it’s a class, but everything inside of it is stored in a map, that’s more flexible!”

    In any case, this code starts by using the [] accessor on a member variable m_pTHINGY. This operator returns a reference to what’s stored at that key, or if the key doesn’t exist inserts a default-constructed instance of whatever the map contains.

    What the map contains, in this case, is a pointer to a THINGY, so the default construction of a pointer would be null- and that’s what they check. If the value is null, then we erase the key we just inserted and return false. Otherwise, we return true. Otherotherwise, we return false.

    As a fun bonus, if someone intentionally stored a null in the map, this will think the key doesn’t exist and as a side effect, remove it.

    Gaetan writes:

    What bugs me most is the final, useless return.

    I’ll be honest, what bugs me most is the Hungarian notation on local variables. But I’m long established as a Hungarian notation hater.

    This code at least works, which compared to some bad C++, puts it on a pretty high level of quality. And it even has some upshots, according to Gaetan:

    On the bright side: I have obtained easy performance boosts by performing that kind of cleanup lately in that particular codebase.

    [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Articlepycodestyle – Python style guide checker
    Next Article Benchmarking the Firefly AIBOX-3588S Embedded Fanless PC

    Related Posts

    News & Updates

    Microsoft wants you to chat with its browser now – but can you trust this Copilot?

    July 28, 2025
    News & Updates

    I tested the Dell XPS’ successor – here are the biggest upgrades (and what’s the same)

    July 28, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Secure GUI VPN for Kali Linux

    Learning Resources

    CVE-2025-39445 – Highwarden Super Store Finder SQL Injection

    Common Vulnerabilities and Exposures (CVEs)

    How Much Does It Cost to Build a White-Label Enterprise Performance Management Software?

    Web Development

    canvural/larastan-strict-rules

    Development

    Highlights

    CVE-2025-5636 – PCMan FTP Server Buffer Overflow Vulnerability

    June 5, 2025

    CVE ID : CVE-2025-5636

    Published : June 5, 2025, 5:15 a.m. | 1 hour, 42 minutes ago

    Description : A vulnerability, which was classified as critical, has been found in PCMan FTP Server 2.0.7. This issue affects some unknown processing of the component SET Command Handler. The manipulation leads to buffer overflow. The attack may be initiated remotely. The exploit has been disclosed to the public and may be used.

    Severity: 7.3 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Flaws Found in Hitachi Energy’s MicroSCADA X SYS600: CVEs Could Enable File Tampering, DoS, and MITM Attacks

    June 24, 2025

    Canonical Announce Big Changes to Ubuntu Summit

    May 27, 2025

    This security-minded Linux distribution makes it easy to browse anonymously

    July 14, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.