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

      From Data To Decisions: UX Strategies For Real-Time Dashboards

      September 13, 2025

      Honeycomb launches AI observability suite for developers

      September 13, 2025

      Low-Code vs No-Code Platforms for Node.js: What CTOs Must Know Before Investing

      September 12, 2025

      ServiceNow unveils Zurich AI platform

      September 12, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 2025

      Distribution Release: Q4OS 6.1

      September 12, 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

      Optimizely Mission Control – Part III

      September 14, 2025
      Recent

      Optimizely Mission Control – Part III

      September 14, 2025

      Learning from PHP Log to File Example

      September 13, 2025

      Online EMI Calculator using PHP – Calculate Loan EMI, Interest, and Amortization Schedule

      September 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      sudo vs sudo-rs: What You Need to Know About the Rust Takeover of Classic Sudo Command

      September 14, 2025
      Recent

      sudo vs sudo-rs: What You Need to Know About the Rust Takeover of Classic Sudo Command

      September 14, 2025

      Dmitry — The Deep Magic

      September 13, 2025

      Right way to record and share our Terminal sessions

      September 13, 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.

    <span class="hljs-function"><span class="hljs-type">bool</span> <span class="hljs-title">DataManager::thingyExists</span> <span class="hljs-params">(string name)</span>
    </span>{
        THINGY* l_pTHINGY = (*m_pTHINGY)[name];
        <span class="hljs-keyword">if</span>(l_pTHINGY == <span class="hljs-literal">NULL</span>)
        {
            m_pTHINGY-><span class="hljs-built_in">erase</span>(name);
            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
        }
            <span class="hljs-keyword">else</span>
        {
            <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }
    

    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 Corporate Computer Naming Policy

    Related Posts

    News & Updates

    Building personal apps with open source and AI

    September 12, 2025
    News & Updates

    What Can We Actually Do With corner-shape?

    September 12, 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

    CVE-2023-28909 – Skoda MIB3 Bluetooth Integer Overflow Remote Code Execution Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-48780 – Soar Cloud HRD Deserialization Command Execution Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-13952 – ASPECT Predictable Filename Information Disclosure

    Common Vulnerabilities and Exposures (CVEs)

    Hash-o-matic – generate, compares and verify MD5, SHA-256 and SHA-1 hashes

    Linux

    Highlights

    CVE-2025-9750 – Campcodes Online Learning Management System SQL Injection Vulnerability

    August 31, 2025

    CVE ID : CVE-2025-9750

    Published : Aug. 31, 2025, 11:15 p.m. | 2 hours, 13 minutes ago

    Description : A security flaw has been discovered in Campcodes Online Learning Management System 1.0. This vulnerability affects unknown code of the file /admin/login.php. The manipulation of the argument Username results in sql injection. It is possible to launch the attack remotely. The exploit has been released to the public and may be exploited.

    Severity: 7.5 | HIGH

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

    Linux laptop lagging? 5 simple ways to speed it up fast

    April 16, 2025

    Chinese Hackers Exploit Trimble Cityworks Flaw to Infiltrate U.S. Government Networks

    May 22, 2025

    CVE-2025-48121 – Steve Puddick WP Notes Widget Cross-site Scripting

    May 16, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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