C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

4
votes
0answers
12 views

Another even Fibonacci numbers implementation

This is intended as something of a comparative study. I'm including not just one, but two separate implementations of code to implement the Project Euler problem to sum the even Fibonacci numbers up ...
4
votes
2answers
68 views

Project Euler 23: Non Abundant Sums

Here is my solution to Project Euler 23: Non Abundant Sums. I know I'm doing the Divisors function brute force, but I can't seem to get it to work any other way. ...
3
votes
1answer
45 views

'any' class implementation

I have made an any class in C++, base loosely on boost::any, but written differently. I am checking to see if I have done it ...
2
votes
1answer
32 views

select_best: yet another partitioning algorithm

The title is somewhat a misnomer; my apologies. The goal of the procedure is to partition a range of first, last by mid for the ...
2
votes
1answer
62 views

Optimizing Sudoku solver in C++

Recently, I wrote a Sudoku solver in C++. My program is very hard and was solved in a few seconds. In my opinion, this is slow. ...
0
votes
0answers
12 views

OpenGL/Glut Cant draw on it [on hold]

I'm working on a really simple OpenGL Project. I'm trying to simulate Newton's law of universal gravitation. This code is not finished yet. I already created the particles, and I added the drawing ...
6
votes
5answers
117 views

Convert sequence of number into display string

My requirement is to convert a sequence of numbers into a display string as below. Example Input 1,2,3,4,5,7,7,8,8,8,10,15,10,11,12,88,87,86 Output 1-5,7-8,10-12,15,86-88 ...
-1
votes
0answers
14 views

Using linked list to make a simple version of word/sentence predicting software (e.g T-9) [on hold]

Hey Guy/Gals, I want to develop a simple program using linked list/trees for predicting words or sentences WITHOUT using file handling because i haven't been taught file handling yet ...
4
votes
2answers
156 views

Reading a file and storing the contents in an array

This is my code for reading a file with a delimiter. Any suggestions to help improve my code efficiency? I am not satisfied with using array data structure. Can any other data structure be used ...
4
votes
0answers
40 views

Tree implementation for unordered keys

The following is an implementation of a tree in C++ designed for keys which do not have an order (otherwise a std::map could be used). ...
0
votes
0answers
24 views

Number of disc intersections [closed]

I've been trying to get a working solution in C++ to the number of disc intersections/"beta2010" Codility training test (found here or here). I realize my solution isn't very efficient but I can't ...
4
votes
3answers
243 views

Tic Tac Toe in C++

Here is my two-player Tic Tac Toe game. How can I improve it? ...
1
vote
0answers
28 views

(nearly) lock-free job queue of dynamic size (multiple read/write)

After, analysing what went wrong in lock-free job queue without size restriction (multiple read/write) I've come up with another solution, here's what it does: ...
8
votes
1answer
142 views

Is my C++11 generic container a good design?

After refactors and refactors and the discovery of very common patterns on many of the classes of the software I wrote, I decided that it would be fine to have something like an arbitrary-keyed map, ...
4
votes
3answers
92 views

Parsing httpline

I have an HTTP server class (.hpp & cpp). I am trying to improve reserve data from the socket class because I have s.getline() to get HTTP call. My ...
7
votes
2answers
72 views

Tree Template Class Implementation for C++

I have not done any parameter checking, however I think the meat of the class is there. Let me know what you think. ...
4
votes
2answers
103 views

Project Euler Problem 11: Largest product in a grid

Here is my implementation to project Euler Problem 11. I did this problem a bit later, when I learned how to input from a txt file. The problem context can be seen here. I did add "\n" to the end of ...
1
vote
0answers
29 views

Follow-up: Timer utilizing std::future

The previous code (as displayed in Timer utilizing std::future) is now: ...
7
votes
0answers
111 views
+100

Sprite drawing class

I have written a very XNA spritebatch like interface for drawing sprites in OpenGL. When begin is called the vertex data buffer is mapped to a float*. The index buffer and vertex buffer are bound in ...
4
votes
3answers
301 views

Project Euler 18/67: Maximum Sum from Top to Bottom of the Triangle

This is my attempt at Project 18/67 of Project Euler. You can see the problem information, and obtain the needed txt file from here. I had some help with the split function, and help on how to use an ...
6
votes
3answers
99 views

SDL/C++ Pong clone

This is my first time writing a game in C++/SDL and I decided to post the code here so you can tell me what I am doing wrong. main.cpp ...
7
votes
4answers
80 views

Optimize RecvData wrapper

How can I improve the string RecvData() function? ...
11
votes
3answers
209 views

Insertion Sorting in C++

From Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, ...
25
votes
7answers
3k views

Conway's Game of Life in C++

This is my attempt at Conway's Game of Life. It works, and it's the most complicated program I've made to date. I'm sure it's pretty poorly done. Any ideas on how I can improve on it? ...
8
votes
1answer
102 views
+50

AnySetValue - a set of with multiple types of values

I would like a review for this code which is used apparently successfully in my current project. More info are available in this gist but I'm pasting here the main info: The project use C++11/14 ...
6
votes
0answers
89 views

A simple Thread Pool

A very simple Thread pool: Any work added to the pool will be executed. The destructor will wait for all work to be finished before letting the threads stop. We then join all threads before letting ...
3
votes
2answers
68 views

Delegate and Observer pattern implementation for an embedded system

I'm writing a set of simple widgets for a microcontroller application. I'd like to use the observer pattern to pass around events: when a button is clicked, when a timeout occurs - there are many uses ...
8
votes
2answers
445 views

Compile time decorator pattern in C++ with templates

I'm doing some high energy physics modelling in C++. I have written code that implements class that score interactions of particles with detector material. Here is a base class: ...
4
votes
2answers
81 views

Project Euler 14: Longest Collatz Sequence

I've brute forced solve Project Euler 14. This is my first attempt at trying to solve it, by caching already solved answers, and skipping them as I run it, I am finding the program take's almost twice ...
6
votes
1answer
53 views

Generic radix sort

This started out with my answer to Radix Sort on an Array of Strings?. Since I intend to write a generic radix sort for my own purposes anyway, I continued a little bit, and here is a version tested ...
7
votes
3answers
127 views

Parallel sieve of Eratosthenes, version 2

This question is a revision of Parallel sieve of Eratosthenes. The goal is to implement a sieve of Eratosthenes with parallel strikes out from the boolean array. I tried to fix the data races and all ...
1
vote
0answers
37 views

Leverage C++ Type Inference and basic Reflection library

I've just finished my fist iteration on a type inference and basic reflection library for C++, which is part of a small game engine I'm writing on my spare time. It features type instantiation by ...
19
votes
5answers
1k views

Parallel sieve of Eratosthenes

For the first time, I tried to use threads by myself in order to implement a parallel sieve of Eratosthenes. The trick is that each time a prime is found, a thread is spawned to eliminate all the ...
4
votes
2answers
97 views

Counting matrices

I need help optimizing my code to run faster (it works but I get Time Limit Exceeded) for this problem. (Don't pay attention to readInt() function, its only used ...
4
votes
2answers
87 views

User input and reading contents of file

For full disclosure: this is an assignment for my programming class and I just want tips or advice on some of the code. Assignment details just for background information purposes: Write a ...
1
vote
0answers
14 views

What is the pattern for a safe interface in C++ [migrated]

Note: the following is C++03 code, but we expect a move to C++11 in the next two years, so we must keep that in mind. I'm writing a guideline (for newbies, among others) about how to write an ...
6
votes
7answers
807 views

Project Euler #3 - largest prime factor

I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of ...
0
votes
0answers
12 views

How to use the strategy pattern with STL containers? [migrated]

Assume that I have a strategy interface named BinaryClassifier that can take a Sample and return a ...
9
votes
3answers
723 views
6
votes
1answer
71 views

Timer utilizing std::future

I have a Timer class executing a function in a specified interval: ...
9
votes
1answer
88 views

Free a binary tree without using recursion or allocating memory

As the title says, the objective is to free a binary tree without using the stack or allocating memory. This was required for a kernel module where resources were limited. Result has a complexity of ...
8
votes
2answers
80 views

Container for list of ranges

I made a C++ container of an ordered list of integers, that, in order to save space, I save as ranges: For example, the list \$ \{1,2,3,5,6,7,8,9,20\} \$ is saved in memory as \$ \{(1,3), (5,9), ...
5
votes
1answer
111 views

lock-free job queue without size restriction (multiple read/write)

I've since come up with an improved version, which isn't technically lock-free, but might be as close as you can get (nearly) lock-free job queue of dynamic size (multiple read/write) code below is ...
3
votes
1answer
55 views

Lockfree ThreadPool implementation

How could this template class ThreadPool be improved? I use Boost queue to keep std::function's numbers from ...
3
votes
1answer
73 views

Format string inline

For this project, I do not have access to Boost or C++11. Note: I updated the question's description to clarify what I am doing. I have not changed the code though, so no answer has been invalidated. ...
12
votes
4answers
956 views

Prime Number Generator - Are the conventions proper?

I am slowly learning C and C++, and decided after a few lessons to dive in myself without any help. I developed this Prime Number generator. It seems fast, but I'm wondering if I'm following the best ...
7
votes
2answers
296 views

Chef and Digits

I am looking for a review on the following code which is for this question. I am looking for a general review of the code. I am specifically also looking for advice on how to make this code run more ...
5
votes
1answer
87 views

C++11 Logging Architecture

To create a Logging system for a larger application, I came up with the following draft. The log sinks aren't detailed yet, but the factory method for logger creation and a rough draft of the logger ...
6
votes
1answer
55 views

Dynamically call lambda based on stream input: Try 3

Based on Dynamically call lambda based on stream input: Try 2 This fixes most of the points pointed out by @Morwenn. It has been generalized so anybody can call it. The only extra part needed by the ...
6
votes
2answers
66 views

Generic Multiway Merge

Recently I had a problem (not in C++) that required merging a number of sorted lists of values. This is effectively the generalised case of merging together two sorted lists. However, instead of ...