Minimal Rust-inspired C++20 STL replacement. Refer to the blog post for details.
Goals:
To use rpp in your project, run the following command (or manually download the source):
git submodule add https://github.com/TheNumbat/rpp
Then add the following lines to your CMakeLists.txt:
add_subdirectory(rpp) target_link_libraries($your_target PRIVATE rpp) target_include_directories($your_target PRIVATE ${RPP_INCLUDE_DIRS})
To use rpp with another build system, add rpp
to your include path, add rpp/rpp/impl/unify.cpp
to the build, and add either rpp/rpp/pos/unify.cpp
or rpp/rpp/w32/unify.cpp
based on your platform.
The following configurations are supported:
OS Compiler Arch Windows MSVC 19.39+ x64 Linux Clang 17+ x64, aarch64 macOS Clang 17+ x64, aarch64Except for MSVC on Windows, the gcc vector extensions (also implemented by clang) are used to emit SIMD operations. On Linux, other architectures should therefore work, but they have not been tested.
Other configurations (GCC, etc.) may be added in the future.
#include <rpp/base.h> using namespace rpp; i32 main() { assert(true); info("Information"); warn("Warning"); die("Fatal error (exits)"); }
#include <rpp/base.h> #include <rpp/rc.h> #include <rpp/stack.h> #include <rpp/heap.h> #include <rpp/tuple.h> #include <rpp/variant.h> using namespace rpp; i32 main() { Ref<i32> ref; Box<i32> box; Rc<i32> rc; Arc<i32> arc; Opt<i32> optional; Storage<i32> storage; String<> string; String_View string_view; Array<i32, 1> array; Vec<i32> vec; Slice<i32> slice; Stack<i32> stack; Queue<i32> queue; Heap<i32> heap; Map<i32, i32> map; Pair<i32, i32> pair; Tuple<i32, i32, i32> tuple; Variant<i32, f32> variant{0}; Function<i32()> function{[]() { return 0; }}; }
#include <rpp/base.h> using namespace rpp; i32 main() { using A = Mallocator<"A">; using B = Mallocator<"B">; { Vec<i32, A> a; Vec<i32, B> b; info("A allocated: %", a); info("B allocated: %", b); Box<i32, Mpool> pool; info("Pool allocated: %", pool); Region(R) { Vec<i32, Mregion<R>> region{1, 2, 3}; info("Region allocated: %", region); } } Profile::finalize(); // Print statistics and check for leaks }
#include <rpp/base.h> using namespace rpp; i32 main() { Profile::begin_frame(); Trace("Section") { // ... } Profile::end_frame(); Profile::iterate_timings([](Thread::Id id, const Profile::Timing_Node& n) { // ... }); }
#include <rpp/base.h> using namespace rpp; struct Foo { i32 x; Vec<i32> y; }; RPP_RECORD(Foo, RPP_FIELD(x), RPP_FIELD(y)); template<Reflectable T> struct Bar { T t; }; template<Reflectable T> RPP_TEMPLATE_RECORD(Bar, T, RPP_FIELD(t)); i32 main() { Bar<Foo> bar{Foo{42, Vec<i32>{1, 2, 3}}}; info("bar: %", bar); }
#include <rpp/base.h> #include <rpp/thread.h> using namespace rpp; i32 main() { Thread::set_priority(Thread::Priority::high); auto future = Thread::spawn([]() { info("Hello from thread %!", Thread::this_id()); return 0; }); info("Thread returned: %", future->block()); }
#include <rpp/base.h> #include <rpp/pool.h> #include <rpp/asyncio.h> using namespace rpp; i32 main() { Async::Pool<> pool; auto coro = [](Async::Pool<>& pool) -> Async::Task<i32> { co_await pool.suspend(); info("Hello from thread %!", Thread::this_id()); co_await Async::wait(pool, 100); co_return 0; }; auto task = coro(pool); info("Task returned: %", task.block()); }
#include <rpp/base.h> #include <rpp/vmath.h> #include <rpp/simd.h> using namespace rpp; i32 main() { Vec3 v{0.0f, 1.0f, 0.0f}; Mat4 m = Mat4::translate(v); info("Translated: %", m * v); auto simd = SIMD::F32x4::set1(1.0f); info("Dot product: %", SIMD::F32x4::dp(simd, simd)); }
To build rpp and run the tests, run the following commands:
Assure MSVC 19.39 and cmake 3.17 (or newer) are installed and in your PATH.
mkdir build cd build cmake .. -DRPP_TEST=ON cmake --build . ctest -C Debug
For faster parallel builds, you can instead generate ninja build files with cmake -G Ninja ..
.
Assure clang-17 and cmake 3.17 (or newer) are installed.
mkdir build cd build CXX=clang++-17 cmake .. -DRPP_TEST=ON make -j ctest -C Debug
For faster parallel builds, you can instead generate ninja build files with cmake -G Ninja ..
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4