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.

Filter by
Sorted by
Tagged with
3
votes
1answer
41 views

How to optimize the code snippet which has several calls to find method that is to read files and load them into the map?

I wrote a functionality to read files and load them into the map m_fileParams. Then I am searching the specific keys in the map container using ...
1
vote
0answers
23 views

Limit framerate [on hold]

I have made this class. Not sure if there is anyway to make it better. It seems to work alright half the time, but other times frames jump up higher then the set limit around 30frames more if i set it ...
2
votes
0answers
25 views

C++ Sql-like base operating on csv files

I implemented very constrained trivial implementation of sql querries operating on user files (in csv format). Where possible i tried to use modern C++ features. The fancy goal is to serve MySql ...
3
votes
1answer
55 views

Multithreading Ticket class to wait for parallel task completion

I've implemented a "Ticket" class which is shared as a shared_ptr between multiple threads. The program flow is like this: parallelQuery() is called to start a new query job. A shared instance of ...
4
votes
1answer
52 views

Reading from a stream but reserving N bytes at the end of stream

What I'd like to do is read data from a stream (like ifstream::read), but reserve N = 4 bytes from being returned. The last 4 bytes of the stream are not part of the data itself, but are metadata. In ...
3
votes
1answer
58 views

Stereo image matching implementation in Halide

The authors of this paper compute support_points of a 900×700 image in 118 ms. I have implemented their algorithm below in Halide. In my algorithm, the nested for loops over length and width iterate ...
3
votes
1answer
38 views

Producer consumer with threads and using boost ring buffer

I have two threads, one is the producer and other is consumer. My consumer is always late (due to some costly function call, simulated in below code using sleeps) so I have used ring buffer as I can ...
2
votes
1answer
114 views

generic flyweighting function

I made this little function for flyweighting any type that has operator<. I followed the convention of make_unique and ...
5
votes
0answers
72 views

A straightforward method for computing the Binomial probability mass function

I've been writing up code to test an alternate way of calculating the Binomial probability mass function. The Binomial random variable is the number of heads out of N coin tosses with coins that have ...
1
vote
1answer
62 views

A minimalistic kind of read-copy-update class

This is a very simple read-copy-update (RCU)-inspired synchronization class: ...
1
vote
1answer
63 views

Boolean class using shared referenced memory

To improve my knowledge I am trying to make a bool class from scratch, or derivative of. I am using MinGW g++11 compiler on a Windows 7 laptop. ...
4
votes
0answers
51 views

C++ simple inter-process notification system

I needed to synchronise several processes, so I developed this ipn::Notifier class that uses a mutex+condition variable stored in shared memory to notify all ...
3
votes
1answer
63 views

Predefined values for some values in a template function like with a #define macro (e.g. template<int foo, typename bar>)

I want to overload an operator (e.g. operator<<) with different types, but also change only 1 or 2 values in the function itself. I want to get some fancy output of a vector with the primitive ...
5
votes
3answers
1k views

A STL-like vector implementation in C++

I'm implementing a STL-like vector with the essential functionalities. I would like to know what is good in this code and what is bad. In terms of everything (memory usage, functions implementations, ...
2
votes
0answers
124 views

Event management system in C++

I have this question asked as home assignment for an interview. I submitted my solution and did not get selected. Wanted to know your feedback for the solution. Question: Write a very simple ...
7
votes
1answer
119 views

Parallel Ramanujan's formula for 1/π calculation

I finished my university project for calculating \$1/\pi\$ and I would love to get some feedback. Before you guys jump into this code please keep in mind newcomer to C++ just decided to use it for ...
9
votes
2answers
1k views

Implement Own Vector Class in C++

I am preparing for an interview and came to know about this question: implement a vector class in C++. I thought of how I would write it an interview and included the code below. The things I know I ...
-1
votes
1answer
59 views

Determine if matrix exists or not [closed]

any help with optimizing following code to make it run faster. Tried making function inline, tried cin.TIE(NULL), tried ios_base::sync_with_stdio(false); ...
9
votes
3answers
93 views

Console Blackjack game, without split or betting system for now

I never programmed in my life, and I am currently self teaching myself some C++ by reading books, online free classes and googling. After beginning to read about OOP and classes, and after seeing that ...
5
votes
2answers
121 views

Templated division by a power of 2

I've implemented a div_by_power_of_2() function, which lets me force the compiler to use left-shifting rather than proper division, in cases when the developer know ...
1
vote
0answers
42 views

Functions like std::stoi for unsigned and shorter types using __gnu_cxx::__stoa

C++11 introduced the new standard library function std::stoi, unfortunately there is no equivalent function to convert an unsigned number inside an std::string to ...
4
votes
1answer
105 views

Simple ring/circular buffer c++ class V3

The Original Post (v2) As stated in the previous post, i'm looking for feedback on the updated version of the code posted. A few things specifically I'm looking for feedback on, are: I switched to ...
2
votes
2answers
81 views

Simple ring/circular buffer c++ class V2

The Original Post (v1) I'm looking for feedback on the updated version of the code posted at the link above. ...
4
votes
1answer
148 views

STL Performance micro-benchmark

I'm fairly new to C++, so as a learning exercise for how to use various simple data structures efficiently and what I should and shouldn't avoid, I wrote the following code: ...
3
votes
1answer
82 views

Elevation to power function using class templates

I attached below a small working example of a function that is able to perform x^y. As it is possible to see the base (x) takes ...
2
votes
2answers
41 views

Graph library - graph interface

I am trying to write simple graph lib in C++, BFS, DFS etc.. I want to create class GraphI which will represent any graph and will include necessary methods so my ...
3
votes
2answers
129 views

Merge Sort C++11 C++17

Question Any way I can optimize this further using new C++11 or C++17 features? Would also like feedback on my variable naming, memory management, and style (notice my placement of ...
3
votes
0answers
46 views

Multithreaded OpenGL Rendering Pipeline

I've decided to move my rendering code to a separate thread, to help facilitate the move I've created a pipeline system for rendering. With this pipeline I can insert commands into a queue which will ...
3
votes
1answer
46 views

Iterative version of a permutations algorithm

For learning purposes, I've written an iterative version of a recursive algorithm for generating the set of permutations for a given set of unique integers. Can I make any improvements to increase ...
6
votes
3answers
984 views

Array Dynamic resize in heap

I have answered a Question in Stackoverflow link. a) Create a function called resize that can be used to increase the size of integer arrays dynamically. The function takes three parameters. ...
1
vote
1answer
51 views

Get a map containing elements which are present in unordered map A but are not present in unordered map B [closed]

I would like to create a function which returns a map containing differences between two unordered maps. Here is the code: ...
3
votes
2answers
122 views

Mario Party Snake and Ladders Board

Context Was inspired from this LeetCode post to do my own System Design exercise of the common Snake and Ladders problem. As I was writing the code Mario Party kept coming to mind so I added a little ...
1
vote
0answers
25 views

Average histogram combining multiple files and vector of vectors (in c++)

I run a program of simulation N times (I use each time a different random numbers to initialize it). The results of the program are stored in 2N directories: every run produces two approximations. The ...
4
votes
1answer
55 views

Min heap C++ implementation

I have implemented a min heap in C++, and I want to improve it in every possible way. Could you please review it and let me know your suggestions/comments? ...
3
votes
1answer
37 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
92 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
130 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
81 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
144 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
111 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 ...
9
votes
2answers
234 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
79 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
126 views

Replace unicode character in the string

A function which replaces an unicode character in a string: ...
10
votes
1answer
465 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
358 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
189 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
74 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
793 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
170 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? ...