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

learn more… | top users | synonyms

6
votes
1answer
16 views

Homebrew std::string for use with kernel

I've ported some standard library facilities like vector, algorithm, etc. to my kernel so I can code in C++ instead of C. This is one of them. I'm looking for concerns regarding: Performance Safety ...
4
votes
0answers
24 views

A tiny switcher for arbitrary types in C++11

I was about to use the awful enum+map trick to switch on std::strings when I thought to see if I could let some variadic templates do the job for me and I started ...
4
votes
0answers
10 views

Normalize Sparse Matrix along rows in C++ Eigen

I wrote a function to normalize sparse matrix along rows using C++ Eigen; however, I feel that it can be improved, and that I am not using some built in functions of Eigen. ...
5
votes
4answers
251 views

Binary Search Tree C++ Implementation

I've implemented a simple binary search tree for practice purposes: ...
0
votes
0answers
28 views

Mini eCommerce Application and Message/Warning/Error Handling

I decided to build a basic eCommerce application in C++ as a learning experience. In the past, I've gone with a fat controller, skinny model approach, and while it has worked, my results always end up ...
0
votes
2answers
122 views

Really basic terrain generator

This is my first attempt at writing a c++ program, so bear with me. I tried to use as many methods as I learned in about a week-long period. ...
3
votes
1answer
39 views

DateTime internal representation to FILETIME

Here is a routine I put together to convert SQL Server's internal DateTime representation (BINARY(8)) to a ...
5
votes
2answers
79 views

A tuple unpacking macro that approximates Python elegance

Motivation Although I love coding in C++, I sometimes yearn for the syntactic sugar of Python. C++11 has somewhat eased the pain by such beautiful analogies like this: ...
7
votes
3answers
162 views

Function to convert from const char * to char**

I made an adapter function to convert a const char * to char ** splitting the words in the initial string at each white space ...
2
votes
1answer
59 views

Cutting stock recursion

This problem is identical to the one here: Suppose that you have been assigned the job of buying the plumbing pipes for a construction project. Your foreman gives you a list of the varying ...
4
votes
2answers
74 views

begin() vs rbegin(): how can I avoid duplication?

Can the display function be re-written to avoid duplication of the std::for_each loop? ...
0
votes
1answer
69 views

Implementation of inheritable pImpl idiom and MVC pattern

I am trying to write an object "template" that use pImpl and MVC pattern to encapsulate everything not specific to the object. The following is how I tried to attempt it. I am sure that the code ...
7
votes
1answer
80 views

Sorting objects to be rendered by their state

I'm writing a renderer to learn my way around OpenGL and right now I'm trying to understand how to sort the objects to be rendered. As I understand there are a few rules to this: Sort to minimize ...
-2
votes
0answers
20 views

c++ zero on a button [closed]

I am asked to restrict a button on a program. By using another restricted one, I added a few lines and restricted it. But one of lines was adding 0 for when we have nothing on the button. When we ...
2
votes
2answers
51 views

Optimizing a particle filter weighted selection step

I have a vector with 10000 particles that I use in a Particle Filter. The problem is that it's taking too long to compute the weighted selection of the particles. I want to use a vector of weights ...
-1
votes
1answer
43 views

Multithreading - program with lots of parallel routines (C++) [closed]

I'm coding a networking software, which has lots of functions (modules) which can be run in parallel. They share some resouces, like libnet_contexts of every type, ...
5
votes
2answers
115 views

Tic Tac Toe with classes

I have created Tic Tac Toe in c++ using classes. Is this efficient code? And GNU GCC compiler gives these warnings: ...
2
votes
2answers
103 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. ...
4
votes
3answers
658 views

Turning numbers into text

Here is my program that turns numbers into text. It can be extended to millions, billions, trillions and so on. Please review my code and here is what I expect from the users: Is there any better ...
0
votes
0answers
14 views

QSqlDatabase - correct way to handle connection [closed]

What is correct way to handle connections for QSqlDatabase? In my program I am doing it this way: ...
6
votes
3answers
338 views

Clean Code attempt of HOLES problem on codechef.com

The problem asks you to take read an integer (number of words to read) and then process words entered counting the number of "HOLES" exist. Letters with HOLES are ...
3
votes
2answers
37 views

Value Iteration Implementation for MDPs

I've been working for a while on a decision theory library, and since I've never really had any formal training in code best practices I'd love to hear your feedback. This particular class is one of ...
8
votes
3answers
165 views

Scorekeeper for a game

The code is not for any project, I just want to know the best coding practices. The code is also on GitHub. ...
3
votes
2answers
66 views

Emulating __uint128_t

I developed a lot of code locally with __uint128_t only to find out that it is not available on the target platform. I am now trying to write my own struct that ...
6
votes
1answer
53 views

Bitmap problem performance boost

Problem statement: Input is a rectangular bitmap like this: 0001 0011 0110 The task is to find for each black (0) "pixel", the distance to the ...
5
votes
1answer
41 views

File validator configured using XML

I am making an application to check for any files that does not follow a specific pattern defined in a XML file. The application works well, but the source code is not the greatest, and memory ...
6
votes
3answers
559 views

STL Queue Implementation

I've implemented a simple C++ STL like queue. (I've tried to follow @LokiAstari stack implementation code fashion) ...
1
vote
2answers
103 views

Binary search as a generic algorithm

I am upgrading my C++11 knowledge and repeating some essential algorithm. Here is binary search only in terms of iterators. ...
6
votes
2answers
70 views

Diagonal gradient optimization

With the SDL library, I'm creating an SDL_Surface* at w and h dimensions. ...
7
votes
2answers
79 views

Entity management design & smart pointers

I'd like to get some guidance on whether or not I'm approaching my design the correct way, especially with regards to usage of smart pointers and references. I've started developing a small game ...
6
votes
3answers
547 views

STL Vector Implementation

I've implemented a simple vector like STL C++. ...
10
votes
2answers
91 views

Parsing of a (Linux) netlink hotplug uevent packet

The netlink service is used, among other things, to notify userspace about hotplug events (e.g. "a device has been connected"). These events come in the form of packets, which follow the following ...
10
votes
3answers
598 views

Clean code attempt at ATM problem on codechef.com

The problem asks you to take an integer (debit amount) and a double (credit or initial balance amount) and process the requested debit verifying that 1 it's a multiple of the minimum denomimation ...
13
votes
2answers
142 views

Thread pool worker implementation

As an exercise in using C++11 features I decided to make a thread pool class. I would like to have a review on the code with focus on: Standards compliance / Portability issues / Best practices ...
3
votes
2answers
48 views

Creating polls and calculator with custom functions and without any global variable

I solved this problem using custom functions and calling them in main function. The challenge was to avoid global variables. Please note that I'm C++ noob and this program is fairly large. I'm ...
6
votes
1answer
106 views

Bluetooth door-opener program

I've been working on a little project on an Arduino and I need some help with making the code more efficient / cleaner. I really don't like the three for loops. I ...
5
votes
3answers
174 views

Determine whether one vector is a prefix of the other

Exercise 5.17: Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, ...
7
votes
2answers
79 views

Generic absolute value function

I wanted to write a generic abs function that would correctly work for every type. Basically, I wanted to use the following algorithm: If the type is a built-in ...
2
votes
0answers
36 views

Wrapping boost accumulators

Here is a namespace for wrapping boost accumulators for use in a broader code base. I love these accumulators but re-typedefing them everywhere is ugly and a pain. ...
4
votes
1answer
75 views

Cart mover- OOP usage and learning design patterns

Firstly, I would like to say that this site looks fantastic... I haven't tried it out yet, but I'm coming from SO, so I think it will be great. My code is for a simple "cart-creation" class and ...
4
votes
2answers
93 views

Converting a string to various number formats

I'm working on a set of PostgreSQL helper classes, and am representing each PostgreSQL data type as objects. Instead of creating a class for each number format, I've created a template so the user can ...
23
votes
6answers
4k views

Printing lyrics of 99 Bottles of Beer

I wrote a C++ program for 99 Bottles of Beer, but it's kind of messy. Is there any way I can make it short and cleaner and more easier to read? ...
2
votes
1answer
50 views

Producer - Consumer interaction

I have an implementation of Producer-Consumer multi-threaded interaction.It works.But I feel that during the execution wait states happen too often between Consumer ...
9
votes
2answers
428 views

Clean code attempt on codechef.com FCTRL

I have been reading Clean Code and decided to start working problems on Codechef.com attempting to apply some of what I have learned. Do I seem to be on the right track or am I way off? The ...
5
votes
0answers
64 views

PostgreSQL datatypes for libpq in c++

Following on from my earlier question: Very simple PostgreSQL ORM in C++ using libpq (tldr; I'm creating a set of helper classes for working with libpq) I've decided to have another attack at the ...
8
votes
1answer
106 views

Very simple PostgreSQL ORM in C++ using libpq

I'm working on a set of helper classes for working with libpq in C++ and I want to be able to pass in objects to the helper classes and have them internally represented as strings when sent to the db, ...
11
votes
3answers
179 views

Substitution cipher algorithm performance boost

This algorithm is meant to read a string of numbers on an input, a naive substitution cipher code (A = 1, B = 2, ..., Z = 26) and output the number of ways the code could be interpreted (e.g. 25114 ...
3
votes
2answers
69 views

contains() algorithm for std::vector

I wrote the following function for the purpose of reusability: ...
1
vote
0answers
59 views

Optimizing implementation of Dijkstra

I am using a std::priority_queue to implement Dijkstra's algorithm: ...
6
votes
3answers
343 views

Shuffling function using rand()

I would like to hear your suggestions about my shuffling function in C++. I've decided to take advantage of using rand() to build a shuffling function. ...