https://github.com/fabienpean/vectr
A type-erased sequential container to store any kind of type uniformly
https://github.com/fabienpean/vectr
container cpp type-erasure vector
Last synced: about 2 months ago
JSON representation
A type-erased sequential container to store any kind of type uniformly
- Host: GitHub
- URL: https://github.com/fabienpean/vectr
- Owner: FabienPean
- License: mit
- Created: 2020-09-29T21:11:41.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-29T22:18:42.000Z (almost 6 years ago)
- Last Synced: 2026-01-02T02:24:17.787Z (6 months ago)
- Topics: container, cpp, type-erasure, vector
- Language: C++
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# VECTR
## Example
```cpp
#include "vectr.h"
#include
#include
int main()
{
using namespace vectr;
std::unordered_map map;
map[0] = vecter::create();
map[1] = vecter::create();
map[0].vector().push_back(3.14);
map[1].vector().push_back(42);
map[0].vector().push_back(1.44);
for(auto& v: map[0].vector()) std::cout << v << " ";// prints "3.14 1.44"
for(auto& v: map[1].vector()) std::cout << v << " ";// prints "42"
}
```
## What?
This repository provides an experimental container which is attempts to be a generalized sequential container. Each `vecter` can store any type and can be safely rebind to store other types.
## Why?
For fun and education primarily.
A more concrete application is to reduce the amount of indirections for _data frame_ kind of containers. In general, they rely on data structure with a minimum of two indirections. Given in term of (simplified) C++, as a `map>`. This container leads to a single indirection by replacing the `unique_ptr` by the type-erased content of a `std::vector`
## How?
`vecter` is inherited by `vecter_impl`. The former contains 32 bytes of information which describes its content, while the latter type provides the methods to interpret correctly its content.
* a pointer to a structure containing general information and methods on the actual type stored (size, alignment, destructor, etc)
* a pointer to the beginning of the buffer
* a pointer to the end of the existing content within the buffer
* a pointer to the end of the whole allocated buffer
The user is responsible to know what type is stored in a `vecter` to be able to use it. However, the basic operations such as destruction/copy/move are safely done.