Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bertptrs/safelist
A memory-safe linked list in C++
https://github.com/bertptrs/safelist
c-plus-plus data-structures linked-list memory-management
Last synced: about 1 month ago
JSON representation
A memory-safe linked list in C++
- Host: GitHub
- URL: https://github.com/bertptrs/safelist
- Owner: bertptrs
- License: mit
- Created: 2017-08-08T18:10:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-24T14:23:21.000Z (over 7 years ago)
- Last Synced: 2024-11-12T20:35:30.941Z (3 months ago)
- Topics: c-plus-plus, data-structures, linked-list, memory-management
- Language: C++
- Homepage: https://bertptrs.nl/2017/08/26/memory-safe-linked-lists.html
- Size: 84 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# safelist -- An memory-safe linked list in C++
[![Build Status](https://travis-ci.org/bertptrs/safelist.svg?branch=master)](https://travis-ci.org/bertptrs/safelist)
This repository contains a header-only reimplementation of `std::list`
using the memory constructs introduced in C++11. The goals of this
project is as follows:- Have a delete-free implementation of a linked list
- Prevent use-after-free memory errors
- Prevent dangling pointers
- Prevent memory leaksOther problems, such as null-pointer dereferencing are still very much
possible and will still occur, but will be more predictable.## Usage
The `safelist` is designed as a drop-in replacement for `std::list`, so
replacing it should not be a problem. Include [safelist.hpp](safelist.hpp)
wherever you would normally include `list`, and change your types
accordingly.Not everything is implemented exactly as it is in `std::list`. Key
differences are:- Allocator is not specifiable, and is the default allocator
- Features are lacking according to what it says in
[Progress](#progress)
- Not all typedefs are implemented
- Not all undefined behaviour works the same way. For instance,
iterating past the end causes a loop back to the start.
- The move variant of `merge()` is missing, because there is no real
benefit to it in this implementation.
- The move variant of `splice()` is missing for the same reason.## Progress
### Basic use
- [x] Empty constructor
- [x] Count constructor
- [x] Range constructor
- [x] Assignment operators
- [x] Push back/push front
- [x] Emplace back/emplace front
- [x] Pop back/pop front
- [x] Iterators
- [x] Const iterators
- [x] Reverse iterators
- [x] Const reverse iterators
- [x] Insert at iterator
- [x] Emplace at iterator
- [x] Delete at iterator
- [x] Sizing
- [x] Resizing### Comparisons
- [x] Equality/inequality
- [x] Greater than/less than### Algorithmic use
- [x] sort
- [x] merge
- [x] splice
- [x] remove (if)
- [x] reverse
- [x] unique## Why would you do this?
I learned about C++ smart pointers but since the main things I write
code for are university assignments (not a lot of memory management in
general) and programming contest submissions (no need for readable,
maintainable code) so I never looked into it.For the summer I wanted a programming challenge to do, so here it is.