Šimon Tóth’s Post

View profile for Šimon Tóth

C++ Educational Content Creator | 20 years of Software Engineering experience distilled into digestible daily posts

C++20 added the method contains() to associative and unordered containers. This method checks for the presence of an element, simplifying the typical pattern of invoking find() and comparing against the end iterator. Compiler Explorer link: https://lnkd.in/dGzcV9KT #cpp #cplusplus #coding #programming #dailybiteofcpp

  • text
Sayan Bhattacharjee

SUKRA HELITEK INC9K followers

2y

Is there a conditional bounds checking accessor method for std::vector? at() provides bounds checking, but it's slow for performance critical codes. operator [ ] is extremely fast, but I have continuously introduced out of bounds access bugs using it. A best solution would be something that allows bounds checking to be enabled/disabled at compile time. I didn't find anything in STL, so I'm just thinking of implementing something myself.

Dimitri Kudriashov

Simicon (Traffic Enforcement…487 followers

2y

I think i is may be useful when you simply check for an absence of the element. But if for example I want to get the key value form a map I also need to find the element again (via at() or []). The pattern with auto iter = dict.find(...); iter->second ... does the job faster a bit.

Saad Ahmed

Edvisor.ai917 followers

2y

Took them long enough

Stefano Fiorentino

adesso Schweiz AG3K followers

2y

Is there the generic std::contains(c1, 0)? [as per c1.begin() vs. std::begin(c1)] If not, why not?

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories