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".

Filter by
Sorted by
Tagged with
2 votes
1 answer
133 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
  • 123
4 votes
1 answer
104 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
  • 111
2 votes
1 answer
82 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
113 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
  • 243
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
149 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
146 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
664 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
526 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
  • 1,995
2 votes
1 answer
76 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
3k 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
50 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
139 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
6 votes
2 answers
153 views

Insert into any sorted container

The following is my attempt to implement a insert_sorted() C++ function that accepts any sorted STL container and item and inserts it at the right position in the ...
Alessandro Morelli's user avatar
3 votes
1 answer
92 views

Function to use projections in legacy algorithms [closed]

I love the "projections" introduced by the ranges library, and I would like to use them in algorithms that haven't been rangeyfied yet. I had the idea of using them through a function like ...
metalfox's user avatar
  • 133
2 votes
1 answer
1k views

std::vector Allocator-Aware Implementation

I've just finally finished implementing std::vector. I'm currently re-implementing whatever I can in the hope to learn more of how data structures works. I tried to ...
SomeoneWithPassion's user avatar
2 votes
3 answers
2k views

Generic Vector implemented in C language

I am on the way implementing my own STL-like library in C language. The main reasons are learning DS&A better, as well as the C language itself. Here I am trying to implement Vector (a.k.a. array-...
khasanovasad's user avatar
5 votes
2 answers
571 views

Custom STL Vector container Implementation

For practice purposes, I reimplemented a STL Vector container. This container has most/all of the capabilities of STL vector.In my previous post, the reviewers made critical and concised observations ...
theProgrammer's user avatar
5 votes
1 answer
542 views

C++ code for Priority Search Tree

I'm trying to implement a Priority Search Tree(PST) following this note: http://cs.brown.edu/courses/cs252/misc/resources/lectures/pdf/notes07.pdf. For convenience, ...
mining's user avatar
  • 235
5 votes
2 answers
336 views

C++ Practice on STL templates and algorithms

I have implemented the following program below for an assignment for practice on STL templates and algorithms. All I'm doing is implementing the code for the printing of empty files, un-empty files, ...
starrk's user avatar
  • 369
3 votes
0 answers
89 views

STL compatible Binary Search Tree with unique_ptr (unit test included)

I am trying to create a Binary Search Tree, which has STL support (iterators etc.). This is my first attempt. Everything is unit tested using Catch2. Could you please review what I missed and what I ...
MartenBE's user avatar
  • 131
1 vote
1 answer
190 views

Implementing boost::upgrade_mutex using only standard locks

Is this my_upgrade_mutex class a valid implementation of boost::upgrade_mutex semantics? (Ignoring the ...
zwhconst's user avatar
  • 137
3 votes
1 answer
54 views

An implementation of maximum subarray finding algorithm in STL style

I am reading Stroustrup now and I was very impressed with how flexible the STL library is thanks to iterators and generic programming. Along the way, I am also reading Cormen's book and decided to try ...
apollo1840's user avatar
3 votes
1 answer
84 views

Records and elements class, small "database" c++, no sql

I'm trying to construct a simple database for use by 2 persons only (myself and other guy), right now, we're using excel table with 4 fields "requisition, origin date, request date and authorized date"...
Vital Zero's user avatar
5 votes
1 answer
273 views

Iterating over a tuple

I tried to write a small header-only library that provides a type similar to iterators for std::tuple as well as some STL-like algorithms. I would be grateful for ...
n314159's user avatar
  • 153
5 votes
3 answers
567 views

SequencedMap which retains insertion order - Design#2

UPDATE: Current best state of a solution incorporating feedback and further development is in this answer. Review on this Design#2 please: Simple wrapper class template for ...
Oliver Schönrock's user avatar
6 votes
1 answer
2k views

Wrapper class template for std::map + std::list to provide a SequencedMap which retains insertion order

Review on this draft please: clang-8 -std=c++17 Simple wrapper class template for std::map & std::list (or alternatively std:unordered_map & std::vector) for the purpose of "retaining ...
Oliver Schönrock's user avatar
3 votes
2 answers
86 views

Average of subarrays of length k in C++

I took a crack at solving the problem of finding the averages of all subarrays of length k. Here is what I came up with. I would greatly appreciate your feedback on my code. ...
Reza Afra's user avatar
  • 171
5 votes
3 answers
4k views

A custom String class implementation

This is my first implementation of a "container" using the Rule of Five, any feedback I'll gladly accept. I've tried to make it as Exception-Safe as possible. I've made it for an assignment. Header <...
Styn's user avatar
  • 53
2 votes
1 answer
105 views

Merge adjacent occurrences of identical elements in data collection

There is a small programming exercise to merge adjacent identical elements in a collection. Here are two solutions (passing the tests from the exercise). I am asking for review of the first version ...
user avatar
11 votes
2 answers
264 views

YAAI (Yet another any implementation)

I am a C# game developer currently learning C++ and this is my second big-ish project (the first one being a vector implementation). This time I opted for implementing a mot-a-mot ...
Marius T's user avatar
  • 381
17 votes
2 answers
359 views

YAVI (Yet another vector implementation)

I am a C# game developer currently learning C++. I am trying to implement some simplified STL containers. Here is my implementation of vector, which does not have the allocator (because ...
Marius T's user avatar
  • 381
5 votes
4 answers
3k views

static_vector: a vector with stack storage

In many cases, we want a variable-size array like std::vector, but we know an upper limit on the size. In such cases, the vector can be allocated on the stack. We ...
L. F.'s user avatar
  • 9,456
6 votes
1 answer
1k views

A standard-conforming C++17 std::optional implementation

I took quite some time to implement a fully standard-conforming std::optional in C++17. It turns out more sophisticated than I initially thought. My code is just ...
L. F.'s user avatar
  • 9,456
8 votes
2 answers
237 views

for_each_cons and for_each_slice, variants of std::for_each working on sliding windows

My goal was to replicate Ruby's each_cons and each_slice: ...
Adrian17's user avatar
  • 231
9 votes
1 answer
5k views

Continuation Implementation in C++11

While playing with the concurrency features in C++11 I noticed that there wasn't any support for continuations. I wanted to develop something similar to Tasks in The Parallel Patterns Library (PPL), ...
Eóin Ó'Flynn's user avatar
1 vote
1 answer
2k views

Track execution time using std::chrono facilities and print the execution time in a comprehensible way

The class below will be used to track the execution time of various operations. There is no need to dip into C libraries to get formatted output then. Output would be something like this: 10 ...
Atul Kumar's user avatar
4 votes
2 answers
254 views

Is_permutation() on sequence containers in O(n) complexity - follow-up

This question is a continuation of my previous question: Check is_permutation on a pair of same sized arrays. I improved the implementation to generalize for all sequence containers. Please let me ...
Steephen's user avatar
  • 1,250
6 votes
1 answer
2k views

STL-like palindrome checking

I just read this article on how to write a standard-like algorithm and wanted to try it myself by writing (as suggested in the article) an algorithm to test if a sequence given by two bidirectional ...
johannes's user avatar
14 votes
2 answers
8k views

Fixed-size block allocator

I have written a fixed-size block allocator implementation and would like some feedback as to what I could improve in my code and coding practices. Your comments or notes are welcomed! An auxiliary ...
se0808's user avatar
  • 303
2 votes
0 answers
835 views

Max independent set of a sequence

This is the code I've written to find the maximum-weight independent set of a graph path. It's a standard problem with a well-known dynamic programming solution of linear complexity. Since it's a ...
Vladimir Sinenko's user avatar
3 votes
1 answer
20k views

Multiply vector elements by a scalar value using STL and templates

I wrote a small scientific simulation where I wanted to manipulate vectors with the same kind of functionality that Python's NumPy vectors use. Namely, I wanted to be able to add vectors together, ...
Hooked's user avatar
  • 227
10 votes
5 answers
1k views

Simple server to manipulate priority queues

In a few months I'll work on a C++ project that could span a year or two. I've a strong C background and for the usual reasons I always chose C over C++ (please forgive me). To extend my capabilities ...
Yorick de Wid's user avatar
12 votes
2 answers
1k views

Object storing and retrieving using wildcard identifier

I'm writing an interpreter for a scripting language which allows objects to: Have an alias Be referenced using a wildcard Contain child objects Combination of all three above For example: ...
Mislav Blažević's user avatar
2 votes
1 answer
2k views

Enum list to STL container

Can someone improve upon this function of mine? EnumToSTLContainer is supposed to make a copy of any STL container whose elements are from a specified ...
prestokeys's user avatar
  • 1,351
6 votes
4 answers
2k views

Counting word occurences

This is a simple word count program I wrote to play around and get familiar with using std::map. Is there anything I can improve upon? I didn't use CTRL+Z to stop ...
Quaxton Hale's user avatar
  • 2,629
5 votes
3 answers
2k views

"Jolly Jumper" challenge

I'm a C#/Java full-time developer who is trying to pick up C++ purely for educational reasons. I've tried to solve a pretty simple ACM ICPC problem and would love to hear all kinds of criticisms on ...
TtT23's user avatar
  • 1,040
4 votes
2 answers
20k views

STL List Implementation

I've implemented a simple C++ STL like list. It's pretty simple, all the constructors and methods haven't been implemented here, but majors are. ...
Kaidul Islam's user avatar
7 votes
2 answers
2k views

Using includes() vs. hash function to check if an unordered_set is a subset of another unordered_set

I did two methods to determine if an unordered_set is a subset of another unordered_set, using hashing, and the built-in ...
phoenix's user avatar
  • 73
4 votes
1 answer
140 views

Container which iterates a range or a list

I have made some composited container Range which accepts either a min/max range as a std::pair or a set of integers as a ...
Gabriel's user avatar
  • 323