Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [c++11]

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

1
vote
0answers
9 views

A matrix-vector multiply parallelized using boost::MPI

This program performs a matrix-vector multiply using MPI to split the computation up. It is not extremely robust (for example, it doesn't handle the case where the number of MPI processes does not ...
6
votes
1answer
67 views

Qt Number Generator v2

Link to the old question. I tried to learn some new things from the answers and here's what I did: Used Qt Designer so that in Config.h, all member variables and ...
4
votes
0answers
54 views

C++ shared_ptr memory pool

I put together this little memory pool class to help avoid the costs associated with heap allocation and deallocation of objects that are frequently created & destroyed. It creates C++ standard <...
4
votes
2answers
62 views

Simple device (fancy) pointer implementation

device_raw_ptr is a simple fancy pointer. It essentially wrap pointers to GPU memory. It's sole purpose is to separate out host pointers from device pointers, i.e. ...
6
votes
1answer
119 views

Implementing a queue: questions and clarification

Im trying to teach myself some computer science (and c++). I am relatively new to this (and to code review). I have attempted to implement a queue. I have copied the code below for reference. ...
2
votes
1answer
74 views

Cache with limited size; If full remove the oldest

Here is a class that stores a single value into the limited cache. If cache is full, it will remove the oldest element to make a space for a new value. I'm using 2 structures to accomplish this ...
15
votes
3answers
3k views

Modeling an IPv4 Address

I've recently picked up a book that gives various "modern" C++ challenges/solutions. One of the first ones I did was on modeling an IPv4 address in C++. Below is the full implementation; it's also on ...
8
votes
2answers
89 views

Creating a lock-free memory pool using C++11 features

I have created a thread-safe and lock-free memory pool program using C++11 features. A couple of notable features: g_memStack is a stack that contains the memory ...
3
votes
1answer
77 views

Effective message dispatching [closed]

I have some code, that works fine. However, I know there is a lot of code duplication and C-style programming. In the code example there only is a ...
4
votes
2answers
71 views

Replace unicode character in the string

A function which replaces an unicode character in a string: ...
11
votes
1answer
251 views

Google Kickstart Round A 2019 - Training

Problem: Training As the football coach at your local school, you have been tasked with picking a team of exactly P students to represent your school. There are N students for you to pick ...
8
votes
2answers
282 views

Finding all intervals that match predicate in vector

I have a function find_all_intervals_below that iterates through a vector and finds all the index intervals of at least a given length where each element within the ...
4
votes
1answer
175 views

Reverse int within the 32-bit signed integer range

Problem Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Optimized code here. Feedback I'm looking for any ways I can optimize this with modern C++ ...
5
votes
1answer
59 views

Passing uint64_t from C++ to R: Hilbert Mapping - xy2d function

I have been working with Rcpp to perform a forward and backward Hilbert Mapping. Below is an implementation based on this code. My application is in genomics and I may be dealing with enormous ...
5
votes
3answers
782 views

Stack Interview Code methods made from class Node and Smart Pointers

Mainly looking for feedback on my use of smart pointers to implement a standard stack. For interview level production code I have also include a namespace and asserts to test my class, let me know if ...
5
votes
1answer
90 views

Quad Tree Implementation in C++11

The following source code is working Quad Tree Implementation in C++11. How can I simplify the source code but also allow the user to bring his own Point Class Implementation? ...
5
votes
1answer
75 views

wrapper for common subset of auto_ptr and unique_ptr API

I read an interesting old question on the Software Engineering SE about how to transition away from std::auto_ptr. So I wrote a wrapper around the common subset of <...
0
votes
0answers
17 views

Recursive data-types, binary tree, list-initialization

I have copied the techniques used by https://github.com/nlohmann/json to define a class BSTNode<T> which represents binary search trees and is possible to ...
4
votes
1answer
106 views

std::vector free list

I'm trying to implement a free list by using a std::vector as its growable buffer. The reason I made this instead of just adding/removing elements directly into a ...
6
votes
3answers
86 views

Program that outputs binary values of input

I am looking to simplify my main() function. The nested if statements contain four lines of the same code, and I'm unsure of how to refactor and simplify it. I was attempting to use booleans, which ...
2
votes
1answer
42 views

Queue Interview Code basic methods made from struct Node optimized

Using feedback from my previous implementation I'm writing a very simple Queue of struct Nodes with only these methods get_front(), get_back(), pop_front(), push_back(), and a ostream friend method. I ...
6
votes
1answer
101 views

std::string like compile-time const char* string

I want to write a very simple std::string like compile-time const char* string. I need to work with strings in the compiletime, just like with strings, I implemented basic functions. ...
1
vote
1answer
60 views

Finding index in list in C++

I need to find correct index in a array by comparing ranges. Here is my first try: ...
1
vote
2answers
56 views

shared_ptr basic implementation for non array types

This is an implementation to simulate the basic functionality of c++ shared_ptr. This doesn't provide features like custom deleter and make_shared(). I would really appreciate any feedback to improve ...
3
votes
3answers
115 views

Linked List Interview Code methods, runtime, and edge cases refactored

In my previous post I had a number of steps given to me from the accepted answer on how I can write more production ready code. In this post I want this code to be reviewed as near production code I'd ...
2
votes
3answers
98 views

Queue Interview Code basic methods made from struct Node

Thanks for all the feedback, I optimized the code here. Here I'm Writing a very simple Queue of struct Nodes with only these methods get_front(), ...
1
vote
1answer
73 views

Linked List Interview Code methods, runtime, and edge cases

Refactored code here I want to write a very simple Linked List with only 3 methods Append, Remove and Print. This is not for production and is to be treated as code that could be used in an interview ...
7
votes
5answers
697 views

Vector-transposing function

I profiled a library I'm writing that uses vector transposes and found that I am spending a good bit of time doing the following transpose. I am using a std::vector ...
0
votes
2answers
83 views

Binary Search Tree implementation with unique pointers

I have implemented a binary search tree using templates and unique_ptr in C++ 11. At present, only insertion and deletion are implemented. Please provide your feedback for improvements. ...
2
votes
2answers
107 views

Implementing a binary tree in C++ using “std::unique_ptr”

I have implemented a simple binary search tree class in C++ using std::unique_ptr objects to hold the pointers to each node. In doing this I have come across a ...
3
votes
1answer
79 views

C++ String class implementation

I wrote a simple String class implementation using unique_ptr and move semantics. Is my implementation good enough in terms of design and efficiency? Stringy.h <...
0
votes
0answers
25 views

Create a simple job system using a mutex-locked task queue

Although an experienced gameplay programmer, I'm relatively new to multithreading. I've attempted an implementation of a job system that my WIP 2D engine uses: it provides "engine" and "game" workers, ...
1
vote
2answers
75 views

Inserting an object pointer to a two-level map

I'm working on requirement that involves creating a N x N table of blocks, with each block having a weight. Consider the following classes Block - The fundamental ...
2
votes
0answers
8 views
3
votes
1answer
104 views

Adaptive Merge Sort in C++

As the title says, I'm trying to implement a merge sort algorithm in C++ that's also adaptive. This is a personal exercise, and I don't have any specific application in mind. My main goal is to ...
1
vote
1answer
112 views

Calculating array size in C++

This code shows two ways to calculate size of array of any type. I would like to know, which should be preferred? Is there any advantage/disadvantage? ...
7
votes
2answers
82 views

Rearrage sequence so that adjacent numbers add to perfect squares

Consider the array: original_array1[17] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17} I want to sort it in such a way that: Sum of adjacent numbers should be a ...
2
votes
0answers
74 views

Program to take a number from 0 to 9 as input

I'm trying to make a function that requests a number from 0 to 9 to the user and that is robust. I've been looking at code to guide me and most fail to find any of these situations, usually due to the ...
8
votes
3answers
993 views

Binary Search Tree implementation using smart pointers

I have implemented below code for binary search tree implementation using shared pointer. At present, I have considered only integers. It supports insertion and deletion of values. Also, a print ...
1
vote
3answers
76 views

Password generator class and CLI

I made a password generator class in C++. I am not as familiar with C++ as I am with C, so I am looking for ways to move to a C++ mindset. I am also trying to use embedded practices like avoiding ...
0
votes
2answers
69 views

Find whether two (or 'n') particular values are present in a binary tree

I have a solution to find if two values are present in a binary tree (not a BST). I would like to know if there is a more efficient way to do this? a more elegant way to this? specific improvement ...
4
votes
1answer
97 views

Symbolic algebra using a generic smart pointer class

I am trying to implement a minimal symbolic algebra library (AKA C.A.S.) in C++ that allows me to utilize delayed evaluation similar to this question from SO. My class hierarchy is getting a little ...
2
votes
0answers
39 views

Thread-safe sensor interface with observer and strategy patterns

I have a thread-safe API for an observable Sensor. The concrete type of the Sensor is chosen in the ...
4
votes
1answer
189 views

A header only class for C++ time measurement

I wrote a header only class (actually there is a second one for data bookkeeping and dumping) to measure the execution time of a C++ scope without worrying too much about boilerplates. The idea being ...
6
votes
2answers
109 views

Given a string S and a set of words D, find the longest word in D that is a subsequence of S

I'm trying to improve my code and algorithm to find out the longest word from a dictionary occurring as the sub-sequence in the given string. Example : For example, given the input of S = "abppplee"...
2
votes
1answer
55 views

Loop over whole array starting from any index

I recently had to repeatedly iterate over an array but increment the index to start from each time. Since this is quite cumbersome in comparison to a normal for loop I made a small template function ...
6
votes
1answer
117 views

unique_ptr basic implementation for single objects

This is an implementation to simulate the basic functionality of unique_ptr. This doesn't provide features like custom deleter and ...
5
votes
2answers
109 views

C++ Maybe<T> implementation

In order to improve my understanding of C++ template meta-programming, SFINAE, references, and overall class design, I've tried to implement a Maybe<T> class ...
8
votes
2answers
934 views

C++11 Vector with move semantics

I am practicing move semantics and placement new by writing a custom Vector class but I am not confident that I use them right. I would really appreciate some pieces of advice regarding my code. Here ...
-4
votes
3answers
114 views

Making vector push-front improved to O(1) / 8192

After working on it, my regenerating reserve vector may not be so bad after all. (In this stackoverflow question, I presented a vector with a regenerating reserve, faster at ...