Some parts of C++ require parts of the C++ Standard Library. We’ve lightly touched on classes like std::initializer_list
and std::typeinfo
already, but today we’ll look at a whole lot more. We’ll see parts of the Standard Library that would typically be built into the language or are otherwise strongly tied to making use of particular language features.
Posts Tagged comparison
List<T>
(and SafeList
) have a great feature for fast lookups: BinarySearch
. However, the list needs to be sorted in order to use it. You could call Sort()
first, but that would give back all the performance you got with BinarySearch
. It’s better to just keep the list sorted all the time. Unfortunately, there is no function on IList<T>
, List<T>
, or SafeList
to efficiently insert an item into a list that’s already sorted. Today’s article presents an extension function that adds this functionality on to IList<T>
and even the non-generic IList
so your list will always be sorted for quick lookups with BinarySearch
. Read on for the code, unit tests, and a performance test showing the advantages you stand to gain.