Stack Exchange Network

Stack Exchange network consists of 174 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

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
1answer
92 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? ...
6
votes
2answers
62 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
794 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
65 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
66 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
90 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
35 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
172 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 ...
5
votes
2answers
83 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
51 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
94 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
95 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
921 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
87 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 ...
2
votes
2answers
75 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 ...
2
votes
1answer
71 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 <...
6
votes
1answer
105 views

Tic Tac Toe Game in C++ using Classes

I made a Tic Tac Toe game using classes to show a better approach than the Tic Tac Toe game in Tic Tac Toe in C++11 which works not with classes. I already posted the code there as an improvement ...
1
vote
2answers
38 views

Pairwise swap elements of a given linked list by changing links

GeeksForGeeks challenge: Given a singly linked list, write a function to swap nodes pairwise. For example : if the linked list is 1->2->3->4->5->6->7 then the function should change it ...
3
votes
1answer
111 views

C++ string class implementation, providing support for various C++11 features

This is my implementation of a string class similar to std::string and supports the following: range-for loops iterators basic ...
5
votes
2answers
127 views

Tic Tac Toe in C++11

I wrote this to sort of gauge my understanding of the bare basics of C++.Could you guys give me any pointers? (Ha, get it?). I would happy to hear what you have to say about the code. Also is it neat (...
15
votes
2answers
963 views

C++11 smart pointer 'library'

Edit: NOTE I'm a C++ "beginner" still in undergrad trying to teach myself modern C++ (because they don't do that in uni) so I'm sure this is riddled with errors that I am unaware of. Made a subset of ...
3
votes
2answers
294 views

Text based student information system

This is simple student information system project where you can do following things: Add Records List Records Modify Records Delete Records To store data a .txt file is used. I just want an ...
8
votes
1answer
151 views

Unique compile time (constexpr) type ID without RTTI

I am making a library where I need to generate a unique ID for a type where the ID must be known at compile time. I first relied on the address of a template function, but it proved itself unreliable ...
3
votes
1answer
115 views

value_ptr<T> - a C++11 header-only, deep-copying smart pointer that preserves value semantics for polymorphic and undefined types (updated)

My previous iteration was here. I've since finalized the concept as described in the title, and would appreciate any feedback GitHub Link Introduction: ...
8
votes
4answers
2k views

Most efficient way to find an entry in a C++ vector

I'm trying to construct an output table containing 80 rows of table status, that could be EMPTY or USED as below ...
6
votes
1answer
132 views

Trie Implementation in C++11

I implemented a Trie in C++11, but I am not sure if my usage of struct and std::unique_ptr, and ...
2
votes
0answers
74 views

Rehashing a hash table in c++ with quadratic probing

The code below is my attempt at trying to create a hash table. I'm currently stuck with the rehash function as I think it's not efficient enough (I believe it's O(n^2). I'd be grateful if someone ...
0
votes
1answer
71 views

Matrix arithmetic operations

I am currently attempting to implement Matrix Math for another project I am working on. However, I am not sure whether this implementation will work. Can someone please tell me if there are any ...
3
votes
2answers
89 views

Mockable clock meeting std::chrono TrivialClock requirement and interface

I'm using the time for e.g. ping and timeout calculation as well as animations in a game. So my (big) codebase uses std::chrono::steady_clock::now() in many places. ...
5
votes
3answers
125 views

Singly-linked list data structure implementation

This code seems to work correctly. I would appreciate any comments on how to improve the code, e.g. readability, algorithms, const-correctness, memory, anything else I am forgetting? Also, for the ...
4
votes
0answers
133 views

Trie (dictionary tree) data structure implementation: insertWord, printAllWords, searchPrefix, deleteWord, deleteTrie

This Trie implementation works, however, I would like to get an advice on how to improve this code. Any advice is appreciated: functions implementation, memory management, modern C++ usage, const-...
0
votes
1answer
42 views

Interval scheduling wrapper for Mongoose-OS C timers

I've written a library for Mongoose-OS C mgos_timers. I wanted to write a wrapper to take advantage of the full potential of C++ lambdas. The original C timers ...
4
votes
2answers
176 views

Modeling a parking lot

Here is my code for the design of a parking lot in C++. The following assumptions are made. Referred from Geeks for Geeks The parking lot has multiple levels. Each level has multiple rows of spots. ...
4
votes
2answers
89 views

ROS node to control Dynamixel servo motors

This code is for a ROS (http://www.ros.org/) node that controls a pair of servo motors (referred to in the code as grippers) that can be controlled individually or together. When they are controlled ...
-2
votes
3answers
73 views

Translate a day in year to month and day 2nd method

Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1. I've already submitted my ...
1
vote
1answer
38 views

Implementing a random distribution satisfying RandomNumberDistribution concept

Improving on this code review, I provide logarithmic_distribution to satisfy the C++ RandomNumberDistribution concept implementing the PDF ...
1
vote
1answer
82 views

Translate a day in year to month and day

Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1. This is what I came up with. ...
6
votes
2answers
555 views

Moving elements satisfying a predicate from one container to another

I've implemented a C++ algorithm that moves elements satisfying a given unary predicate from one container into the other, deleting them from the input container. This is my implementation: ...
4
votes
1answer
252 views

Reverse C++11 range-based for loop

I wrote this snippet: ...
7
votes
2answers
212 views

Unit conversion program into metre and stored input

I was curious as to how I'd be able to make this much clearer to read because from my perspective I understand what does what but how does it look to a third party? Also how are my object / method ...
1
vote
0answers
86 views

C++ embedded application to control a light with a timer

I enhanced the my daughter's bed light to IoT. Specifically I can turn the light on/off remotely and there is a timer & alarm function. All of this is implemented with a Particle Photon. This ...
1
vote
1answer
88 views

Implementation of a class that runs a child process with timeout using boost process in async mode

In the following code, I am trying to implement a program that runs a process and returns its return code, stdout and stderr. It ...
3
votes
1answer
50 views

Time series dataset with temporally enforced object lifetime

The purpose of this class is to have that can maintain data set where the samples contained within the set have an expiry time. Samples are inserted in chronological order. In an attempt to memory ...
3
votes
1answer
137 views

Search for rows in a 2D array that contain a given sequence

I have a 2d array of m * n dimension (m and n can vary from 1 to 100000). The following snippet of code checks if the sequence exists in the row and stores the index if it exists. The time taken by ...
6
votes
3answers
137 views

Progress bar wrapper class in C++

I've recently written a simple progress bar class in C++ to mimic usage of similar libraries I've used in Python. The idea is to take some iterable container (e.g. ...
2
votes
0answers
97 views

Yet Another Non-Intrusive Reference Counted Smart Pointer Implementation

I needed a reference counted smart pointer for my project, and for some reason early in my project, I decided that I did not like the std::shared_ptr. I can't ...
3
votes
1answer
75 views

Monitor asynchronous tasks, tracking their running times

Scenario: I'm getting requests through a (thread-safe) queue. Each request then needs to be handled in a separate thread. There is a chance that the function (which is actually calling a Java-program ...
10
votes
3answers
397 views

Implementation of Linux cp in modern C++

This is my simple implementation of the Unix cp command. It is a C++ program but makes use of some of the lower level C library I/O functions. Any suggestions for ...