Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
3
votes
2answers
69 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. ...
4
votes
3answers
85 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 <...
2
votes
1answer
33 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 ...
11
votes
2answers
171 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 ...
16
votes
2answers
249 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 ...
3
votes
4answers
131 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 ...
5
votes
1answer
146 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 ...
8
votes
2answers
199 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: ...
9
votes
1answer
4k 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), ...
1
vote
1answer
1k 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 ...
4
votes
2answers
233 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 ...
6
votes
1answer
1k 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 ...
1
vote
0answers
62 views

A context-based partition_copy

I recently posted a question on Stack Overflow asking how I could go about implementing a context-based partition copy. I actually came up with my own solution, but I would like to see if it could be ...
14
votes
2answers
6k 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 ...
2
votes
0answers
745 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 ...
3
votes
1answer
14k 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, ...
9
votes
5answers
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 ...
12
votes
2answers
925 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: ...
1
vote
0answers
132 views

Enum list to STL container, part 2

Original question: Enum list to STL container Goal: Write a function enumToSTLContainer() that is to return any STL container whose elements are from a specified <...
2
votes
1answer
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 ...
6
votes
4answers
1k 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 ...
5
votes
3answers
1k 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 ...
4
votes
2answers
16k 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. ...
6
votes
2answers
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 ...
4
votes
1answer
136 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 ...
2
votes
1answer
3k views

Filter a collection

In my project, there are some methods which filter some items from a collection. I was told to use the C++ STL whenever I can. But when I use std::copy_if, I feel ...
2
votes
1answer
140 views

LRU Cache with a static variable for garbage value

I have tried to implement a Least Recently Used cache with only C++ STL containers. The main thing that I keep asking my self the static variable called garbage_val....
6
votes
2answers
415 views

STL-compliant list class

This is my first attempt to create an STL-compliant container. I'd like to know whether it meets STL concepts & requirements, so feel free to critique. list.h ...
15
votes
2answers
18k views

Implementation of binary heap in C++

Things I can think of include integer overflow, if the input type is int, etc. But other than that, what do you think is wrong with this code, design-wise, style-wise, and also in terms of other edge/...
6
votes
2answers
1k views

Box-stacking problem in C++

I have tried to write code of Box stacking problem (mentioned here) in C++ . Kindly give me some views on what mistakes I might have made and how I can improve. It is running for the two inputs I have ...
4
votes
2answers
1k views

STL and Dijkstra's algorithm optimization

This is the problem and my solution to this is: ...
4
votes
2answers
714 views

“Edit distance” UVA programming challenge

I'm trying to solve a programming challenge for fun. The programming challenge is here and my solution for the same can be found here. It currently causes an exceeded time limit. ...
0
votes
1answer
4k views

Breadth-first tree traversal using STL list

I am writing code for breadth-first search of a tree with C++'s STL. Please help as I am new to the STL. ...
3
votes
1answer
118 views

copy_if_max() algorithm

I need a copy_if_max() function, i.e. copy all the elements in an input range that are equal to the max in that range. The most obvious implementation does two ...
2
votes
2answers
332 views

Utilizing std::map and std::array for displaying a modulus grid

I've written a modulus-type program (using std::vector). The user inputs a number, and the program displays a modulus grid pertaining to that number. This is what ...
4
votes
2answers
256 views

First use of std::map in factors and prime factorization program

This is from an older question of mine that I decided to revisit: Simplifying and optimizing factors and prime factorization generator In that question, someone suggested I use an ...
2
votes
1answer
548 views

Am I using C++11 features like STL and move semantics correctly?

I've implemented selection sort, heap sort, insertion sort, and iterative quicksort using C++11. Am I using the correct STL data structures/algorithms? Am I using move semantics correctly in my code? ...
7
votes
1answer
428 views

STL-style deque class

I decided to write an STL-style class as an exercise. I followed a tutorial of sorts that I found online, but I also made some modifications. I'd like to hear any criticisms you folks might have. Be ...
7
votes
2answers
15k views

Designing a state machine in C++ using the STL

I have this working code for C++ state machine using STL (not using boost state chart). The purpose of posting is two-fold: To share a simple and working code C++ state machine using the STL for the ...
1
vote
2answers
271 views

unw_graph class (unweighted graph)

Here is my new STL-like implementation of an unweighted graph. Could you please tell me what member functions I should include in my library? unweighted_graph.hpp ...
2
votes
1answer
1k views

Free implementation of “bounded priority queue” in C++

I was searching for a free implementation of a "bounded" priority queue. The algorithm has been discussed many times on Stack Overflow. I took a shot and wrote a STL-like bounded_priority_queue ...
7
votes
1answer
1k views

Setting output width with ostream_iterator

I'd like to display a vector (implemented in my custom Vector class) and have the output width of the elements be configurable. I've done this by creating a simple ...
4
votes
2answers
768 views

C++ and STL - Machine Learning Problem

I would like to get some general comments on style and use of STL in particular. This is some code I wrote to do machine learning classification (logistic regression). Any suggestions would be very ...
5
votes
2answers
4k views

STL-like graph implementation

I have implemented an STL-like graph class. Could someone review it and tell me things that I could add to it? File graph.hpp ...
5
votes
1answer
7k views

Simple object pool template container in C++

The main advantage of this pattern is when I often create and destroy objects, which in this case are often used. I made this because I needed to track several short timers at the same time, but it ...
4
votes
3answers
6k views

Checking if a string is a number with STL

Recently me and colleague had a discussion about the following piece of code (simple bool function that checks if string is a number, +1000 not allowed, ...
4
votes
2answers
22k views

STL graph implementation

I'm looking for a code review on the following C++/STL graph implementation: ...
7
votes
2answers
11k views

Thread-safe std::map accessor

After learning that std::map containers are not inherently atomic and therefore not thread-safe (check out this related Stack Overflow question and usage example), ...
1
vote
4answers
2k views

STL matrix chain multiplication

Please provide positive and not-so-positive feedback on style, clarity, or any other additional feedback you would like to provide. ...
2
votes
1answer
512 views

Reading a sequence of points and finding the closest one to the first

I was told this is the place to come for input/feedback on your programming. I am always looking to improve either by personal review or outside opinion/help. Would the community here be willing to ...