Skip to main content

All Questions

Tagged with
2 votes
1 answer
99 views

Decoupling receiving data and processing data by passing callback and shared_ptr

Sorry for my poor English. I want to decouple receiving data and processing data, this is the demo code: ...
John's user avatar
  • 459
6 votes
3 answers
6k views

dynamic_pointer_cast for std::unique_ptr

dynamic_pointer_cast is only implemented for std::shared_ptr. I need the same functionality for unique pointers. The wrinkle is ...
Diederick C. Niehorster's user avatar
6 votes
2 answers
2k views

shared_ptr and make_shared implementations (for learning)

Recently, I've been going through Scott Meyer's Effective Modern C++ and found the discussion on shared_ptr really interesting. I also watched Louis Brandy's ...
eenz's user avatar
  • 123
1 vote
1 answer
434 views

Implementing a binary search tree using std::unique_ptr

I have implemented a binary search tree with 2 operations to begin with. I have tried to implement it using the best practices I could think of. Overall, I am happy with the implementation. But, I ...
Gaurav Sharma's user avatar
5 votes
3 answers
4k views

Implementing Sample Abstract Factory Pattern using Smart Pointers in C++

Was trying to implement and example code to smart pointer from link. Is it a good practice? To go with all unique pointers or should we use shared pointers in this case? How can i improve this ? <...
Kiran Thilak's user avatar
5 votes
0 answers
1k views

Polymorphic deleter for unique_ptr

There is a basic difference in the way C++ manages the deleter for std::unique_ptr and std::shared_ptr, mainly for allowing ...
Amir Kirsh's user avatar
3 votes
2 answers
640 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 ...
greg's user avatar
  • 1,017
6 votes
3 answers
5k 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. ...
Kiran Thilak's user avatar
3 votes
2 answers
279 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 ...
greg's user avatar
  • 1,017
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
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
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
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
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
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
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
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
15 votes
2 answers
1k 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 ...
sjh919's user avatar
  • 153
4 votes
1 answer
293 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: ...
Tom's user avatar
  • 417
2 votes
0 answers
319 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 ...
Super Cyb0rg's user avatar
5 votes
1 answer
1k views

Graceful thread shutdown with std::move [closed]

I have a thread as part of a class that access the class's data members. The class has a move constructor that moves some of the old class's data members into the new object being constructed. Before ...
Sagar Jha's user avatar
  • 161
1 vote
1 answer
105 views

Single Linked List - simple approach

I am a student, trying to learn C++11 and data structures. I would like to ask you to to review my code. I have spent some time and analyse similar questions on Code Review and it gave me basic idea ...
pb.'s user avatar
  • 133
3 votes
2 answers
4k views

Copy-and-Move Concept Using Smart Pointer

I tried to implement a simple container class using the copy-and-move idiom. I am learning the changes to C++ as of C++11 and later. Is the code exception safe? I chose to use a smart pointer. Is <...
Henning's user avatar
  • 31
11 votes
2 answers
3k views

Trie Data Structure Implementation in C++11 using Smart Pointers -- follow-up

Link to my first question. Link to my latest source code. I followed @JDługosz recommendations. How does it look? Do you have any further recommendations? Is it better (if possible) to replace ...
user avatar
1 vote
1 answer
2k views

Returning containers from function - C++ [closed]

I've been trying to implement a few interfaces for processing data. And most of the time I do new of container and return a smart pointer to this container. ...
Shivendra Mishra's user avatar
1 vote
0 answers
1k views

C++11 CLH Lock Implementation

As a hobbyist programmer I have been reading "The Art of Multiprocessor Programming" (Herlihy, Maurice; Shavit, Nir) and converting the Java spin locks into C++ - I have enjoyed this and learned a lot....
headwedge's user avatar
3 votes
2 answers
1k views

C++11 Singly Linked List with raw pointers

Regarding C++, I have an experience in writing only short non-object-oriented programs and competitive programming challenges. I would like to get your feedback about my C++ style, design decisions, ...
pkacprzak's user avatar
  • 161
16 votes
1 answer
1k views

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

== UPDATED: next revision HERE == My previous two iterations were here and here. I've since finalized the concept as described in the title, and would appreciate any feedback on the new solution ...
Tom's user avatar
  • 417
5 votes
1 answer
248 views

deep_ptr<T>; a header-only, deep copying, value semantic smart pointer for optionally defined types

Edit: final revision here A couple days ago I posted a similar question here. Since then, I have refined the implementation a bit further, as the solution I had previously posited was a bit off ...
Tom's user avatar
  • 417
7 votes
3 answers
5k views

Custom std::shared_ptr<T> implementation

I'd like to get a few pointers about my code. I know that shared_ptr is up and running, and I'm reinventing the wheel but you can't say no to the school assignment. ...
gMD's user avatar
  • 71
14 votes
2 answers
29k views

My implementation for std::unique_ptr

I just finished learning about move semantics and realized that a nice practical example for this concept is unique_ptr (it cannot be copied, only moved). For ...
Matias Cicero's user avatar
10 votes
3 answers
3k views

Implementing a Stack with Templates and Smart pointers

I'm trying to understand the concepts of smart pointers and templates. To get a better understanding of these, I tried to implement these two concepts on Stack. I ...
user3898160's user avatar
4 votes
2 answers
2k views

Implementing a shared_ptr class in C++

I'm trying to write my own shared_ptr/weak_ptr implementation in C++. I have the following requirements: I do NOT need support for the following: multithreading (synchronisation) support for ...
Truncheon's user avatar
9 votes
2 answers
3k views

C++ Linked list with smart pointers

This seems to work fine, but I'm very new to C++ and would like any suggestions for improvements. Areas I have the most trouble with are: Namespacing (honestly, it's still half looking stuff up and ...
Bill Harper's user avatar
6 votes
1 answer
676 views

C++ maybe pointer type implementation

Motivation This is intended to implement a C++ maybe_ptr type that can either hold a pointer to an underlying type T or a ...
n00b101's user avatar
  • 163
2 votes
1 answer
4k views

Thread class that uses std::unique_ptr

I have implemented a class which encapsulates a thread of execution and provides an interface to send messages to it. It is based largely on an article written by Herb Sutter in 2010. It also uses the ...
ksl's user avatar
  • 141
3 votes
2 answers
6k views

Custom STL Vector in C++

This is my first time I tried to implement a custom STL vector with iterator. I have some questions: What are better ways to write an iterator? I know that there is a ...
Newbie's user avatar
  • 700
0 votes
1 answer
3k views

Implementing a single linked list using smart pointers (replace std::shared_ptr with std::unique_ptr)

As an example code I've given here, I have the feeling the use of std::shared_ptr is wrong and should be replaced using a ...
πάντα ῥεῖ's user avatar
1 vote
1 answer
5k views

Smart Pointers Queue Implementation

To practice around with C++11 smart pointers I was trying to implement a simple Queue to go beyond a simple Linked List. The fact that the _first and ...
user49428's user avatar
8 votes
3 answers
243 views

Multiplayer GameObject design

I created a really basic game class. A game has GameObject instances, which currently have a position only. This code is running on the client, and in each loop ...
Iter Ator's user avatar
  • 271
-1 votes
1 answer
4k views

Using shared_ptr as class member [closed]

I have already got the answer for my previous question, and I decided to use std::vector<int> instead of int *. I have ...
AnatoliySultanov's user avatar
1 vote
3 answers
107 views

Implementing my own shared-ownership double-indirecting smart-pointer

I am implementing my own double-indirecting shared-ownership smart-pointer because I needed a way to replace the managed object a group of smart-pointers is pointing to with a new object (it's the ...
user6245072's user avatar
4 votes
1 answer
3k views

C++ lock wrapper class around pointer

I have created a class which wraps pointers and behaves like a pointer would behave, minus a few cases. It is a lock wrapper class which simply locks before usage of the pointer and unlocks once the ...
Andrew's user avatar
  • 143
0 votes
1 answer
206 views

RAII object for releasing pointer with arbitrary function

The following class is a sort of "smart pointer" that can be used for automatically releasing pointers: ...
Jan Rüegg's user avatar
5 votes
2 answers
9k views

shared_ptr code implementation

I have never used std::shared_ptr before and I don't really know how this smart pointer actually works but I decided to create one to verify my knowledge. Here is my code : ...
user avatar
2 votes
1 answer
3k views

List implementation with shared_ptr using C++11

I wrote list, which I think is more elaborate than usual. I would like to ask you for some tips, criticisms, and general feedback about my code. ...
Klemens's user avatar
  • 125

15 30 50 per page