Tagged Questions

C++11 is the successor to the C++03 standard, adding various core language changes and fixes, and an improved and expanded standard library.

learn more… | top users | synonyms (1)

4
votes
1answer
25 views

Get extension(s) from path

I'm writing an utility function that returns the extension(s) of a boost::filesystem::path (v3). Boost's path class already has some of this functionality ...
4
votes
2answers
39 views

Threaded generalised transform

I'm writing an application which works with huge amounts of sequential data, and often found the need to use std::transform. I see two potential improvements to ...
7
votes
2answers
83 views

Sockets and networking for a multi-platform game

I'm in the process of adding network support for a little Mac & Windows game I'm writing. Today I've finished the basic sockets plus a few other network helpers and would appreciate having the ...
1
vote
0answers
43 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 ...
4
votes
1answer
51 views

Adjacency-list graph implementation in C++ (redone from scratch)

I had posted here before, but I decided that the approach used earlier - where every Vertex stores a vector of pointers to ...
3
votes
1answer
85 views

Public interface for nearest neighbor data structures

I am making a small library of metric data structures. That is data structures, which associate points in the n-dimensional space with objects and allow the user to find objects which are closest to a ...
7
votes
1answer
106 views
+100

Refactoring image loading/manipulation class

I have this Image class that I've been using for some time now on personal projects and games I eventually write. It was written in C++98 style and it is starting ...
7
votes
0answers
40 views

Wrapping types with alignment requirements

Visual Studio 2013 still doesn't support the alignas keyword in C++11. This causes some problems with alignment of types in various situations. Thankfully the ...
2
votes
0answers
51 views

GOF Composite Design Pattern Implementation Using Modern C++

After reading about the composite pattern from the GOF design pattern book, I thought to re-implement the code mentioned in the motivation section using the modern C++ concept/idioms. Below is the ...
0
votes
0answers
18 views

Rendering speed in SDL2 [closed]

I have a large rendering class using SDL2: video.cpp (github mirror) It all works fine, except it's a bit slow (starts lagging at larger resolutions). The reason for this is obvious - it basically ...
6
votes
4answers
763 views

String case reverse function in C++

This reverses the case of a character in a string (a string being an array of characters). How does it look? Anything I can improve on? Let's get critical here. ...
11
votes
2answers
119 views

Fast (faster than std::) ostringstream

I tried to implement a faster ostringstream which initially uses the stack (up to 256 bytes before using the heap). Also, unlke the standard, it provides a way to ...
8
votes
0answers
52 views

Function composition using std::bind

Given a number of functions f1, f2, f3, ..., fn I ...
5
votes
1answer
41 views

Formatting database like table

The goal of my program is take some headers and fields and display a nicely formatted table like this: ...
6
votes
1answer
70 views

Is this a correct implementation/use of move semantics?

I'm trying to account for the fact that my program will contain calculations such as: v(t) = w ∗ v(t−1)+ c1∗r1∗( pBest − x(t −1)) + c2∗r2∗(gBest − x(t−1)) where ...
4
votes
3answers
92 views

Basic Encoding Rules (BER) class for embedded system

I'm implementing a communications protocol in an embedded system and the protocol uses a subset of the ASN.1 BER (Basic Encoding Rules). In a nutshell, this class simply represents a TLV triplet ...
1
vote
0answers
43 views

Writing a universal “call” function: call(f, args…) where “f” might be a member function/data pointer

I need a function call(f, args...) which calls the "function" f with the arguments args.... ...
9
votes
5answers
664 views

Find primes using “naive” algorithm

I know I can use Sieves to make this faster, but I wondered if there's anything I'm missing with this implementation of the "naive" algorithm. On my PC running the command (first million primes): ...
2
votes
2answers
113 views

Max path sum algorithm

This is for Project Euler question 18 and I'm looking for feedback on whether my algorithm is incorrect or whether I've just implemented it wrong (which I don't think is the case after some testing). ...
3
votes
2answers
257 views

Squaring numbers in an array

I want to know if there is a better way to square numbers in an array. This is what I wrote: ...
5
votes
2answers
80 views

Writing out a tree of Tnodes with words as values in alphabetical order

I'm doing this: Consider: struct Tnode { string word; int count; Tnode* left; Tnode* right; }; Write a function for entering new words ...
6
votes
4answers
97 views

Efficient prime factorization for large numbers

I've been working on a little problem where I need to compute 18-digit numbers into their respective prime factorization. Everything compiles and it runs just fine, considering that it actually works, ...
5
votes
1answer
128 views

Iterative Fibonacci sequence using standard library functions

We're all aware of Fibonacci sequence calculators but they look like C-style code. I want to avoid that and take advantage of the standard library. This code is very short, so I'm focusing on ...
5
votes
3answers
163 views
2
votes
1answer
58 views

Lockless, blocking, non synchronized multiple producers and consumers ring buffer

My program is structured like this: there are M producer threads, each of which computes a section of an object O with index ...
8
votes
0answers
55 views

Chrono-like clock with different epoch (from 1.1. 2000)

The following will by my simple helper, that should behave just like std::chrono::system_clock but with the epoch being 1.1. 2000, that I can easily cast durations ...
4
votes
0answers
57 views

Eliminating duplication in Python native code function call dispatchers

I attempting to merge 3 functions into one, as they contain for the most part the same code. Here are the original functions: ...
8
votes
5answers
560 views

Probabilistic matchmaking simulation

The following is a problem I found on this wiki. What can I do to optimize my algorithm, and make this code more C++11? Write a program to discover the answer to this puzzle:"Let's say men and ...
6
votes
2answers
241 views

Templated Doubly-linked-list

I've been wanting to revise what I knew on templated classes so thought I'd write a doubly linked list to practice. It works fine, so all is well and good on that front, but is there something I've ...
7
votes
1answer
71 views

Sorting algorithms with utility functions and iterators

My implementation of insertion, merge, and quick sort, with some utility testing functions. I just wanted to know how I can improve the efficiency and general cleanliness of my code. (note: I know ...
5
votes
2answers
141 views

Graph vertex class implementation with adjacency lists

I wrote an implementation of a graph with each vertex storing a std::vector of vertices it's adjacent to. Please critique this. ...
4
votes
2answers
235 views

Project Euler #48 in C++

This question is similar to Project Euler #48 but constraints are different: $$N < 2000000$$ Just in case the link is unavailable, here is the problem statement: We've to print $$\left( ...
5
votes
3answers
360 views

Project Euler #8 - “largest product in a series”

This code works when compiled on gcc 4.8.2. I would appreciate any comments on my style and the readability of my code, and any improvements that I could make to make the code more readable and/or ...
4
votes
2answers
72 views

Wrapper template functions for memset()

I have these three helper functions that I've used on some projects as a slightly better alternative to the C memset function. The objective is to simplify and ...
17
votes
4answers
962 views

The Term-inator: Pi edition

The fourth project, continuing my C++ saga with terrible post names. :P An approximate value of pi can be calculated using the series given below: $$ \pi ...
2
votes
1answer
66 views

Still an observer pattern?

Usually when I see tutorials about Observer Pattern I see an unique method called notify, but I'm wondering. What if I have different methods that can be called in ...
3
votes
1answer
63 views

Program that handles program options

I'm using boost::program_options to parse input from the user. However, while the standard library makes this an easy task to do, it's causing an (in my opinion) ...
1
vote
2answers
69 views

Speeding up and shortening a loop [closed]

I'm still relatively new to C++ and I've written a program that could do with being a bit shorter and faster. I use this same set of for loops many times to cycle through the whole tree of values. ...
3
votes
2answers
179 views

Read binary file by blocks

I wrote a function that allow me to read a binary file using 3 blocks what ever the length of file. I've decided to divide the length of my file into 3: block 1: ______________ block 2: ...
16
votes
4answers
4k views

If she floats then she is not a witch like we thought

Continuing my C++ saga, this is the third project for my CS1 class: Buoyancy is the ability of an object to float. Archimedes' principle states that the buoyant force is equal to the weight of ...
2
votes
1answer
117 views

ComponentManager - Entity-Component-System architecture in C++

Lately I've been working on a small C++ Entity-Component-System framework. Like most other ECS frameworks the internal data is presented as a table where an entity is a simple row index and each ...
5
votes
1answer
85 views
5
votes
2answers
145 views

One-to-many multiplicity pattern

The following working C++11 code demonstrates working code for a pattern for representing one-to-many relationships between objects. GitHub (A variant of that code is also copied inline at the ...
4
votes
2answers
481 views

Convert number into words

I am trying to implement a program which can convert number into words. My code can convert numbers between 0 - 999. It uses recursive function calls and simple arithmetic operations. Can you please ...
5
votes
4answers
209 views

Implementing Conway's Game of Life

Here is an implementation of Conway's Game of Life. My code is working fine but I want you to review and give me your suggestions of how to improve it. These are the steps of my code: Initialize ...
15
votes
2answers
494 views

Lexer+Parser code for my “Reedoo” programming language

I've been working on my own programming language, as a hobby for the past couple of months now, called Reedoo. It is implemented in pure C++ 11 and uses only the libraries that come with C++; no ...
-1
votes
2answers
87 views

LinkedVector : a vector of elements with links to other elements

I wanted to have a vector with usual values and with some sort of indexing : an element can have links to other elements (via indices). Something like the following, where ...
6
votes
2answers
144 views

Policy-based, variadic logger class in C++

I've been exploring design based around some of the more advanced C++11 features lately, and some of them are turning out to be rather useful for some projects I'm working on. One is this ...
2
votes
1answer
108 views

Variadic template data pack strucuture designed for debug/trace log (variable-sized records)

I am currently writing this pack template to pack all the values (raw / fundamental + arrays of such, especially c-strings and ...
3
votes
1answer
43 views

Test if two nodes in binary search tree are cousins

Cousins are nodes at the same level of the tree, with different parents. They don't have to share the same grandparent. My solution depends on having a binary search tree with unique elements. This ...