Questions tagged [c++14]
Code that is written to the 2014 version of the C++ standard. Use in conjunction with the 'c++' tag.
457
questions
0
votes
2answers
140 views
C++ Simple Shared Pointer Implementaion
I wrote an implementation of a shared pointer. I would like a review of it.
It seems to work, but running it through Valgrind shows that that it leaks memory somewhere in my tests, but I don't know ...
4
votes
1answer
104 views
Contacts programming challenge
I successfully solved a problem on Hackerrank called Contacts, but I'm curious if my code in C++ looks good to C++ developers. If not, how it should be improved.
Below is the short description of the ...
3
votes
1answer
63 views
lazy_map implementation in C++ | Similar to unordered_map but O(1) copyable
I implemented lazy_map - https://github.com/tinytrashbin/lazy_map.
Can someone help with reviews ?
lazy_map is an implementation of unordered_map that has O(1) cost
of copying irrespective of the ...
0
votes
3answers
75 views
sorting vector of pair in efficient way
I'm trying to solve the sorting problem but I always get TLE(Time Limit Exceeded/ 1s) so... can you guys suggest a more efficient way to solve this problem?
(i can't link the exercise because it is on ...
0
votes
3answers
66 views
Reversing an array in C++ 14, my second array requires an extra element
Hackerrank problem to reverse an array of size n.
https://www.hackerrank.com/challenges/30-arrays/
Sample Input:
4
1 4 3 2
...
1
vote
1answer
53 views
The Next Palindrome - CodeChef
This is codechef beginner problem.
How I can make it efficient, It is taking 2.09 sec while time limit is 2.0764 secs.
Problem is:
For a given positive integer K of not more than 1000000 digits, write ...
4
votes
1answer
37 views
Solving Tents puzzles using a SAT solver
I built a solver for Tents puzzles using the CaDiCaL SAT solver. The code works and runs quickly, it takes less than 0.1 seconds for a ...
10
votes
3answers
2k views
A Tic Tac Toe game in C++
I am a beginner programmer and have made a tic tac toe program in c++. I need some help with my memory management can anyone review and help me. This is my code
...
5
votes
1answer
99 views
Using Euler-Maruyama method to solve Ornstein-Uhlenbeck equation (SDE)
I am trying to implement the Euler–Maruyama method and use it to solve the Ornstein–Uhlenbeck process. I am basing my code on the wikipedia page where a python implementation is shown. More generally ...
2
votes
2answers
222 views
Reactor pattern in modern C++. Please comment on coding improvements to be done
The reactor possesses its own thread to wait for messages in an event loop.
Users should be able to start or stop the reactor at any point. These two operations are not required to be thread-safe.
...
2
votes
1answer
184 views
Implementing toggle button using Qt
I have below code for implement toggle button.
After including below code, processing power consumed over 90% in my embedded application.
Is there any way to reduce this processing power.
...
2
votes
1answer
81 views
Code to sort based on quantities of a data member occuring
The setup is that I have a vector of a class, and I need to sort it by the quantity of a data member value, not the value itself. The below code exhibits the correct behavior, and part of that ...
7
votes
0answers
98 views
Implementing GSL synchronized_value
Core Guidelines mention a type synchronized_value<T>, which supposedly pairs std::mutex with the internal value. I couldn'...
5
votes
1answer
111 views
Meta functions for sequences of exponents of 2
I have implemented some meta functions to create sequence for exponents of 2. I would love to know if there is any way to make the code more optimized.
Note: ...
2
votes
1answer
78 views
C++ reactor bad implementation
folks.
I have recently started writing software using Modern C++ 11-14. I have been developing software for more than a decade and just wanted to broaden my skillset. I am practicing building some ...
3
votes
1answer
2k views
Simple C++ Telegram Bot
Hi :) I am a beginner coder who just learnt C++ and I wanted to apply it in projects to solidify my learning process. However, I only took a short tutorial before trying this out hence I'm pretty ...
2
votes
1answer
93 views
Generate binary image using coordinate vectors
I have a matrix M of size [n_rows, n_cols] and a list of x and ...
3
votes
2answers
137 views
Benchmarking insertion sort
More than once I claimed that using binary search doesn't improve performance of the insertion sort. For example, see answer here and comments here). Now I have time to substantiate my claim.
The ...
4
votes
2answers
118 views
Rolling median function (Daily Coding Problem 377)
Given an array of numbers arr and a window of size k, print out the
median of each window of size k starting from the left and moving
right by one position each time.
For example, given the ...
23
votes
11answers
8k views
Find nth Fibonacci Number, using iteration and recursion
I'm a beginner programmer and I came upon this problem which is to find the nth number in the Fibonacci series.
I used to solve the problem using a for loop; ...
3
votes
1answer
74 views
Substitution Cipher: Which One?
I'm a beginner and I have a question (somehow silly and stupid :) ). Today I decided to challenge myself and I came around the challenge that wanted me to create a program that ciphers (or encrypts) ...
2
votes
1answer
484 views
Get word frequency of a txt file and save it to linked list
I'm a novice in C++. I want to do three things:
Get the number of lines in the file
Get the number of total words in the file
Get each frequency of each "unique ...
3
votes
1answer
87 views
Unique and shared resource owner
I need a unique_ptr and shared_ptr like structure, but instead of pointers, I would like to store some kind of reference to a ...
2
votes
1answer
111 views
Header only HTTP client library that is a wrapper around CURL
For learning purposes, I wanted to create a header-only C++ wrapper library around HTTP CURL functionality. At the moment the library only implements GET and POST, but I will add other HTTP methods ...
4
votes
1answer
103 views
Signal slot mechanism in C++14
Implementing signal slot mechanism again seems quite
dumb because there are so many people already done this
before but it is for learning and I intended some specific
goals.
I had some library in ...
4
votes
1answer
123 views
Find positive integer with a minimum number of binary 1's such that its bitwise AND with all array elements is not 0
Task
You have an array of positive integers. Your task is to find an
integer x such that the following are true:
Bitwise AND between ...
3
votes
1answer
178 views
Matrix class with overloaded `operator[]`
I have implemented a Matrix class that allocates memory using unique_ptr. How to make it more diverse and optimized in terms of memory usage and efficiency?
...
2
votes
1answer
86 views
Subset Component Task
I've solved a problem Subset Component
Problem
You are given an array with n 64-bit
integers: d[0],d[1],….,d[n-1].
...
2
votes
1answer
80 views
5
votes
2answers
127 views
BrainF**k interpreter in C++
This question is the adaptation of this question in C++. (I'm the author of that code as well).
The code:
...
3
votes
1answer
117 views
Cave Setup for Hunting the Wumpus
I am a hobbyist programmer trying to learn modern C++. My son had an assignment in his C++ class to fill in some functions that populate draw the cave in the "hunt for the wumpus" game. When I viewed ...
17
votes
5answers
9k views
Banking system in C++
I've created a program for Banking System in C++14.
You are given 9 options:
Open Account
Close Account
Show All Accounts
Deposit in Account
Withdraw from Account
Transfer to an Account
Show Balance
...
4
votes
0answers
76 views
Tic Tac Toe with different level AI
I've already created a code in python here with almost the same logic:
Tic-Tac-Toe with changeable board size (Part 1)
Tic-Tac-Toe with changeable board size (Part 2)
Here's the code in C++. As I'm ...
2
votes
1answer
143 views
Prim's Algorithm - Minimum Spanning Tree
I have implemented Prim's Algorithm from Introduction to Algorithms. I have observed that the code is similar to Dijkstra's Algorithm, so I have used my Dijkstra's Algorithm implementation.
Please ...
2
votes
0answers
40 views
A lightweight version of std::shared_ptr<T> V2
This is a lightweight version of std::shared_ptr<T> called res_ptr<T>
This post is a continuation of:
A lightweight ...
7
votes
2answers
373 views
A lightweight version of std::shared_ptr<T>
I wrote a simple lighter version of std::shared_ptr<T> called res_ptr<T>.
...
7
votes
1answer
186 views
An explicit cast for narrowing numeric conversions
Inspired by gsl::narrow_cast, I created my own implementation with the addition of a couple of features:
a static assert on the types to ensure the cast is actually narrowing (if future changes to ...
8
votes
2answers
4k views
Implementation of A* algorithm in C++
I have implemented the A-Star path finding algorithm for a 2D grid. The function returns a list of positions of an acceptable path.
main.cpp :
...
6
votes
3answers
620 views
constexpr SmallVector - std::vector like container on the stack
2 years ago I did this:
SmallVector - std::vector like container on the stack
now, 2 years later, I am reinventing the wheel again, this time with fully constexpr SmallVector.
This time, because I ...
9
votes
3answers
1k views
Count the frequency of integers in an array
I recently reviewed a question here on Code Review. The problem statement is
Write a program that prompts the user to input ten values between 80 and 85 and stores them in an array. Your program ...
4
votes
1answer
221 views
Function composition in C++
My aim was to create a function which behaves like the operator . in Haskell.
Here is what I made:
...
3
votes
1answer
207 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
0answers
62 views
C++14 AtomicRoundRobinPool for sharing a pool of keys
The idea here is that we have some resource that is relatively very expensive to generate, but once we have a bunch of them in a pool, we can keep reusing them instead of generating new ones. "HTTP ...
8
votes
1answer
339 views
Detecting existence of a class member
I wanted to detect if I have a member in a simple POD struct and after some searching and merging some methods I found on the web I've come up with this solution:
...
3
votes
2answers
149 views
“When to take medicine” CodeChef Challenge MEDIC
I just submitted this code to solve the "When to take medicine" challenge on CodeChef:
...
6
votes
2answers
179 views
String manipulation with std::adjacent_find
For the given strings (not containing numbers), print their shortened
versions, where each adjacent sequence of the same characters longer
than 2, change to an expression consisting of a sign and ...
3
votes
2answers
85 views
c++14 move constructor and assignment in simple list
I’m moving from c98 to c++14 and I’m trying to figure out how to write move correctly.
I just wrote the simplest list with no functionality, just testing the construction and copy behavior. I would ...
36
votes
8answers
17k views
Thread Pool C++ Implementation
I have been working on this thread pool for awhile to make it as simple to use as possible. I need some tips on improving performance, and some good ways to test its performance. I was wondering if ...
-1
votes
1answer
61 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);
...
1
vote
1answer
338 views
AVL tree implementation using shared_ptr/unique_ptr
I have implemented an AVL tree using shared_ptr. I know that there is an overhead regarding using shared_ptr and instead a unique_ptr could be used. But the thing is that my node contains also a ...