https://github.com/bluescarni/tanuki
A type-erasure toolkit for C++20
https://github.com/bluescarni/tanuki
concepts cpp20 modern-cpp type-erasure
Last synced: about 1 month ago
JSON representation
A type-erasure toolkit for C++20
- Host: GitHub
- URL: https://github.com/bluescarni/tanuki
- Owner: bluescarni
- License: mpl-2.0
- Created: 2023-09-18T08:44:40.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-02T20:04:03.000Z (about 2 months ago)
- Last Synced: 2025-03-16T22:03:14.204Z (about 1 month ago)
- Topics: concepts, cpp20, modern-cpp, type-erasure
- Language: C
- Homepage: https://bluescarni.github.io/tanuki/
- Size: 5.04 MB
- Stars: 19
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
tanuki
======[](https://github.com/bluescarni/tanuki/actions?query=workflow%3A%22GitHub+CI%22)
[](https://circleci.com/gh/bluescarni/tanuki)

[](https://codecov.io/github/bluescarni/tanuki?branch=main)
A type-erasure toolkit for C++20
Explore the docs »
Report bug
·
Request feature
·
Discuss
> [tanukis](https://en.wikipedia.org/wiki/Japanese_raccoon_dog) are a kind of supernatural beings found in the
> classics and in the folklore and legends of various places in Japan. They are reputed to be mischievous and jolly,
> masters of disguise and shapeshifting but somewhat gullible and absent-minded.tanuki is a small, single-header and self-contained C++20/23 toolkit for
[type-erasure](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Type_Erasure).
Main features include:- high configurability,
- support for both value and reference semantics,
- small object optimisation to avoid dynamic memory allocation,
- the ability to type-erase references,
- support for composite interfaces,
- optional support for [Boost.serialization](https://www.boost.org/doc/libs/release/libs/serialization/doc/index.html).Interfaces are defined and implemented blending the familiar language of
traditional object-oriented programming (i.e., abstract base clasess,
default implementations, single/multiple inheritance, etc.) with C++20 concepts.The elevator pitch
------------------Here is a minimal approximation of [std::any](https://en.cppreference.com/w/cpp/utility/any)
in tanuki:```c++
#include#include
// Interface implementation.
template
struct any_iface_impl : public Base {
};// Interface.
struct any_iface {
template
using impl = any_iface_impl;
};int main()
{
using any_wrap = tanuki::wrap;// Store an integer.
any_wrap w1(42);// Store a string.
any_wrap w2(std::string("hello world"));// Store anything...
struct foo {
};
any_wrap w3(foo{});
}
```[Try it](https://godbolt.org/z/brh6rnnsY) on compiler explorer!
Documentation
-------------The full documentation can be found [here](https://bluescarni.github.io/tanuki).