immer is a library of persistent and immutable data structures written in C++.
Persistent means that when you modify the data structure, the old value is preserved.
Immutable means that all manipulation methods are const
.
An object is never modified in place but a new value is returned instead. Since the old value is still there and it will never change, the new value can transparently keep references to common parts of it. This property is called structural sharing.
Attention
This library is work in progress and its API is not complete enough yet.
A stable release is scheduled for early Q2 2017. This release will use a more liberal license, which is yet to be determined.
Sponsorship
This library is so far a non-remunerated full time job and months of research and development are invested in it. To ensure it’s long term sustainability, we will be launching a sponsoring program in early 2017.
Should your organization be interested in supporting it, contact: raskolnikov@gnu.org.
#include <immer/vector.hpp>
int main()
{
const auto v0 = immer::vector<int>{};
const auto v1 = v0.push_back(13);
assert(v0.size() == 0 && v1.size() == 1 && v1[0] == 13);
const auto v2 = v1.set(0, 42);
assert(v1[0] == 13 && v2[0] == 42);
}
In the last few years, there has been a growing interest in immutable data structures, motivated by the horizontal scaling of our processing power and the ubiquity of highly interactive systems. Languages like Clojure and Scala provide them by default, and implementations for JavaScript like Mori and Immutable.js are widely used, specially in combination with modern UI frameworks like React.
This library is written in C++14 and a compliant compiler is necessary. It is continuously tested with Clang 3.8 and GCC 6, but it might work with other compilers and versions.
No external library is necessary and there are no other requirements.
Note
Some optional modules do have other dependencies, but this is noted in their respective documentation pages.
This is a header only library. Just make sure that the project root is in your include path.
One may generate a development project using CMake:
mkdir build && cd build
cmake ..
To automatically fetch and build all depedencies required to build and run the tests and benchmarks run:
make deps
From then on, one may build and run all tests by doing:
make check
In order to build and run all benchmarks when running make check
,
run cmake
again with the option -DCHECK_BENCHMARKS=1
. The
results of running the benchmarks will be saved to a folder
reports/
in the project root.
This software is licensed under the GPLv3 license.
License header
Copyright (C) 2016 Juan Pedro Bolivar Puente
This file is part of immer.
immer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
immer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with immer. If not, see <http://www.gnu.org/licenses/>.