Skip to main content

Questions tagged [stl]

The Standard Template Library, or STL, is a C++ library of generic containers, iterators, algorithms, and function objects. When C++ was standardised, large parts of the STL were adopted into the Standard Library, and these parts in the Standard Library are also sometimes referred to collectively as "the STL".

5 votes
2 answers
986 views

LeetCode 3366: Minimum Array Sum - w/o DP/memoisation

This program tried to solve LeetCode problem 3366: Minimum Array Sum. It fails for k odd, op1+op2 high enough such there are more odd value to optionally subtract k from than subtractions to allot. A ...
greybeard's user avatar
  • 7,719
1 vote
1 answer
143 views

Number of Islands, C++17, Visual Studio [closed]

I have written a program in C++ to answer the problem of the number of islands. I receive (a path to) a text file that consists of an array where . is water, and ...
MazHoot's user avatar
  • 19
2 votes
1 answer
265 views

Alarm - Timer - Stopwatch with <chrono>

Alarm, timer and stopwatch in the style of the standard library. Important design notes: The accessors do not update internal state, the user is responsible to call ...
demiralp's user avatar
  • 133
4 votes
1 answer
198 views

C++ custom vector class implementation

I've developed a custom vector class in C++, complete with functionalities like assignment, push_back(), emplace_back(), pop_back(), clear(), and size(). I would greatly appreciate any feedback on ...
Jacob's user avatar
  • 131
3 votes
1 answer
139 views

Logger that can be redirected to switch off output

I am evaluating two implementations of a C++ logging mechanism. The first implementation, below, unconditionally streams (calls the insertion operator) to the ...
StoneThrow's user avatar
2 votes
1 answer
158 views

Comparator aware `flat_set` implementation

I am currently implementing a flat_map like container in C++, and had problems with the comparator used. Thus, I reduced it to the bare minimum which I will present here. (In particular, my code here ...
tommsch's user avatar
  • 293
3 votes
2 answers
1k views

Code lines counter

It is a Windows command line utility for counting lines of code in a source code directory. It will count loc and sloc. I read from a file character by character using fgetc in the CountLines(...) ...
mmj's user avatar
  • 31
1 vote
1 answer
206 views

A greedy approach to the Knapsack problem with C++ templates

The assignment is to be implemented on the following instructions: You are to write a Knapsack class and the main() to support and demonstrate the functionality required here. A function generate(int)...
user avatar
2 votes
1 answer
210 views

Reading a list of names, counting them and ordering them

I would like to know does this code follow common best practices in C++ using STL. Goal of the code: There are 10 players that were playing a game 1000 times. Each time someone has won they have put ...
Marko Bošnjak's user avatar
2 votes
2 answers
1k views

Wrapper class to get pairs in range-for loop

This code implements a simple wrapper, intended to be used with range-for to manipulate items of a container as overlapping pairs, ie. 3 items will give 2 pairs. Code review focus: Is ...
hyde's user avatar
  • 205
3 votes
1 answer
866 views

A predicated version of std::for_each

For reasons, I want to implement a predicated version of std::for_each. I know that, in C++20, this is made somewhat redundant or less useful, as we can use ...
einpoklum's user avatar
  • 2,099
2 votes
1 answer
100 views

Implementing a News Ticker

I implemented a console version of a news ticker and I will be glad for a code review. It takes a text from the user and displays it for a given period. How may I get it better? ...
fynnwilliam's user avatar
0 votes
2 answers
4k views

IKM C++ assessment asks about std::unordered_set, part #1 [closed]

Recently I had to do an IKM C++ assessment to qualify for a job. Some of the questions seemed strange to me, so I'll be doing a few posts here to discuss. The first one is related to use of std::...
Tom Naujokas's user avatar
2 votes
1 answer
64 views

convert GCCRandom(Mersenne Twister by Takuji Nishimura and Makoto Matsumoto) to stl random

I am trying to translate the book Game Coding Complete by Mike McShaffry 4E to modern C++17 standard and faced with the code of Mersenne Twister by Takuji Nishimura and Makoto Matsumoto. Is it right ...
Greck's user avatar
  • 23
3 votes
1 answer
181 views

Remove indicies from vector

I am trying to optimise my remove-erase functions by using some attributes of C++ containers. This function should delete all indices defined in std::set form given vector. I am pretty sure that ...
Irimitenkan's user avatar

15 30 50 per page
1
2 3 4 5 6