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 ...
5
votes
3answers
2k views
C++ string_cast<> template function.
In C++, to simplify string conversion between std::string and std::wstring, I created the following utility template functions.
#pragma once
#include <vector>
#include <string>
#include ...
5
votes
1answer
100 views
STL-style deque class, please critique
I'm a C++ newb. 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 ...
4
votes
2answers
217 views
Designing a state machine in C++ using STL, please improve
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 STL for sparse ...
4
votes
1answer
96 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 wrapper for the element being ...
4
votes
2answers
769 views
thread-safe stl map accessor
So after learning that stl map containers are not inherently atomic and therefore not thread-safe (check out this related stackoverflow question and usage example), I decided to create code that would ...
3
votes
2answers
250 views
C++ and STL - Please Critique
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 ...
3
votes
2answers
287 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? Thanks in advance.
File graph.hpp
#include <vector>
#include <list>
using ...
3
votes
1answer
173 views
Counting the total number of characters in a std::set<std::string> ?
I have a std::set and I need to know the total number of characters (sum of all strings length), I created this code:
static size_t SumLength(size_t value, const std::string &str)
{
return ...
2
votes
3answers
129 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, -1000, 1234 ... allowed).
He felt that it ...
2
votes
3answers
168 views
scope exit something wrong?
Is there something wrong with this code?
#pragma once
#ifndef SCOPEEXIT_HPP
# define SCOPEEXIT_HPP
#include <utility>
/* This counts the number of args */
#define NARGS_SEQ(_1, _2, _3, _4, ...
2
votes
2answers
2k views
STL Graph Implementation: Review Requested
Looking for a code review on the following C++/STL graph implementation.
#include <list>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
...
2
votes
2answers
169 views
STL Trying to Be More Generic: File to map Class — Please Critique
So this code will be used to map a set of unique keys to a container of objects that are unique to that key. I would like to be able to reuse this code in future projects hence the template, and not ...
2
votes
1answer
142 views
Polymorphic STL foreach without passing the container type
I was trying to figure out how to make a foreach macro for STL containers that is break-able and I came up with this method that uses templates to recognize the container type automatically. Any ...
2
votes
0answers
116 views
C++ SGI STL pop_heap() method's implementation can be improved like this?
Through the source code, I find SGI STL pop_heap() have three steps:
put the root value into the last;
percolate down;
percolate up.
so pop an element at least require logN(tree's height) swap.
...
1
vote
1answer
336 views
I made a 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 ...
1
vote
2answers
192 views
C++ iterating over unequal unordered pairs in one collection
Here is the code that does what I want:
#include <iostream>
#include <list>
using namespace std;
int main()
{
int arr[] = {1,2,3,4,5,6};
list<int> ...
1
vote
0answers
36 views
maximize assonance in a string(interview question)
Question: Assonance is the reiteration of the same vowel sound at the
beginning of several consecutive words. Assume that each vowel(A, E,
I, O, and U) has only one sound. Prompt the user for ...
0
votes
5answers
574 views
STL Matrix Chain Multiplication Code Review
Please provide positive and not so positive feed back on style, and clarity, or any other additional feedback you would like to provide.
#ifndef MATRIX_H_
#define MATRIX_H_
#include <string>
...
0
votes
1answer
132 views
C++ “Script”: Could I Get Feed Back
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 ...
0
votes
2answers
67 views
Review request: unw_graph class (unweighted graph)
Here is my new stl-like implementation of an unweighted graph. Could you please tell me what member functions should I include to my library? Thanks in advance.
file: unweighted_graph.hpp
#include ...
0
votes
1answer
161 views
Free implementation of “bounded priority queue” in C++ (with code)
I was searching for a free implementation of a "bounded" priority queue. The algorithm has been discussed many times on stack overflow (e.g. Free implementation of "bounded priority queue" ...
-1
votes
0answers
19 views
Ambiguous permutation problem [PERMUT2] [closed]
Consider this question: Ambiguous Permutation. My code is written in C++ 4.7.2
#include<iostream>
#include<vector>
using std::cin;
using std::cout;
using std::vector;
int main()
{
...