Skip to main content

Questions tagged [c++11]

Code that is written to the 2011 version of the C++ standard, sometimes known by its pre-publication name of "C++0x". Use in conjunction with the 'c++' tag.

3 votes
1 answer
232 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 ...
Luciano's user avatar
  • 287
6 votes
1 answer
350 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 ...
sliziky's user avatar
  • 135
5 votes
1 answer
1k 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 <...
Thomas Johnson's user avatar
4 votes
2 answers
224 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. ...
Yashas's user avatar
  • 141
6 votes
1 answer
189 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. ...
Rafael Vergnaud's user avatar
2 votes
1 answer
772 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 ...
Boy's user avatar
  • 121
15 votes
3 answers
5k 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 ...
Developer Paul's user avatar
9 votes
2 answers
2k 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 ...
water's user avatar
  • 93
3 votes
1 answer
95 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 ...
RForce's user avatar
  • 39
4 votes
2 answers
3k views

Replace unicode character in the string

A function which replaces an unicode character in a string: ...
Irbis's user avatar
  • 167
10 votes
1 answer
2k 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 ...
Eric's user avatar
  • 261
8 votes
2 answers
1k 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 ...
Michael Hall's user avatar
5 votes
1 answer
443 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++ ...
greg's user avatar
  • 1,017
5 votes
1 answer
157 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 ...
Lewkrr's user avatar
  • 183
5 votes
3 answers
814 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 ...
greg's user avatar
  • 1,017
5 votes
1 answer
1k 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? ...
user avatar
5 votes
1 answer
155 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 <...
Greg Nisbet's user avatar
4 votes
1 answer
530 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 ...
rashmatash's user avatar
6 votes
3 answers
173 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 ...
J Pex's user avatar
  • 63
2 votes
1 answer
56 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 ...
greg's user avatar
  • 1,017
6 votes
1 answer
723 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. ...
Neargye's user avatar
  • 163
1 vote
1 answer
213 views

Finding index in list in C++

I need to find correct index in a array by comparing ranges. Here is my first try: ...
Ali Nikneshan's user avatar
1 vote
2 answers
154 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 ...
kapil's user avatar
  • 229
3 votes
3 answers
150 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 ...
greg's user avatar
  • 1,017
2 votes
3 answers
124 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(), ...
greg's user avatar
  • 1,017
1 vote
1 answer
594 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 ...
greg's user avatar
  • 1,017
7 votes
5 answers
6k 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 ...
Luciano's user avatar
  • 287
0 votes
2 answers
565 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. ...
bornfree's user avatar
  • 229
10 votes
3 answers
9k 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 ...
tjwrona's user avatar
  • 499
3 votes
1 answer
473 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 <...
Sumit Dhingra's user avatar
1 vote
2 answers
334 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 ...
Inian's user avatar
  • 181
2 votes
0 answers
16 views

QVSquareLayout implementation for Qt that makes all internal items to be squared

qsquarelayout.h ...
outoftime's user avatar
  • 1,729
4 votes
1 answer
408 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 ...
John Lindgren's user avatar
1 vote
1 answer
399 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? ...
bornfree's user avatar
  • 229
7 votes
2 answers
578 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 ...
lithiumhead's user avatar
3 votes
2 answers
233 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 ...
theriver's user avatar
  • 131
9 votes
3 answers
3k 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 ...
bornfree's user avatar
  • 229
2 votes
3 answers
378 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 ...
TenderShortGoldenRetriever's user avatar
0 votes
2 answers
76 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 ...
kapil's user avatar
  • 229
4 votes
1 answer
269 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 ...
Adam's user avatar
  • 185
2 votes
0 answers
299 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 ...
Philippe's user avatar
4 votes
1 answer
582 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 ...
shorty_ponton's user avatar
6 votes
2 answers
300 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"...
Yedhin's user avatar
  • 161
2 votes
1 answer
83 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 ...
HenrikS's user avatar
  • 279
7 votes
1 answer
444 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 ...
kapil's user avatar
  • 229
7 votes
2 answers
4k 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 ...
A P's user avatar
  • 173
8 votes
2 answers
1k 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 ...
user avatar
-4 votes
3 answers
234 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 ...
Saint-Martin's user avatar
2 votes
2 answers
604 views

Dijkstra - shortest Path implementation - STL

I have implemented Dijkstra algorithm to perform Shortest Path problem. Input: Adjacency List(Directed Graph): Description is like that {Source Node, {edge_1, .. , edge_N}} Cost Matrix (Same format as ...
Ricardo_arg's user avatar
2 votes
1 answer
1k views

LRU Cache in C++11

This is a simple and robust LRUCache implementation using doubly linked list and unordered map. It supports .get(), .put(), and <...
happy_sisyphus's user avatar

15 30 50 per page
1
3 4
5
6 7
35