ProductPromotion
Logo

C++ Programming

made by https://0x3d.site

GitHub - TheNumbat/rpp: Minimal Rust-inspired C++20 STL replacement
Minimal Rust-inspired C++20 STL replacement. Contribute to TheNumbat/rpp development by creating an account on GitHub.
Visit Site

GitHub - TheNumbat/rpp: Minimal Rust-inspired C++20 STL replacement

GitHub - TheNumbat/rpp: Minimal Rust-inspired C++20 STL replacement

rpp

Windows Linux Linux (aarch64) macOS macOS (aarch64)

Minimal Rust-inspired C++20 STL replacement. Refer to the blog post for details.

Goals:

  • Fast Compilation
  • Debuggability
  • High Performance
  • Explicit Code
  • Easy Metaprogramming

Integration

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.

Platform Support

The following configurations are supported:

OS Compiler Arch
Windows MSVC 19.39+ x64
Linux Clang 17+ x64, aarch64
macOS Clang 17+ x64, aarch64

Except 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.

Examples

Logging

#include <rpp/base.h>

using namespace rpp;

i32 main() {
    assert(true);
    info("Information");
    warn("Warning");
    die("Fatal error (exits)");
}

Data Structures

#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; }};
}

Allocators

#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
}

Trace

#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) {
        // ...
    });
}

Reflection

#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);
}

Thread

#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());
}

Async

#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());
}

Math

#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));
}

Build and Run Tests

To build rpp and run the tests, run the following commands:

Windows

Assure MSVC 19.39 and cmake 3.17 (or newer) are installed and in your PATH.

mkdir build
cd build
cmake ..
cmake --build . -DRPP_TEST=ON
ctest -C Debug

For faster parallel builds, you can instead generate ninja build files with cmake -G Ninja ...

Linux

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 ...

To-Dos

  • Modules
  • Async
    • scheduler priorities
    • scheduler affinity
    • scheduler work stealing
    • io_uring for Linux file IO
    • sockets
    • use relaxed atomics on aarch64
  • Types
    • Result<T,E>
    • Map: don't store hashes of integer keys
    • Opt: specializations for null representations
  • Allocators
    • Per-thread pools
  • Misc
    • Range_Allocator: add second level of linear buckets
    • Range_Allocator: reduce overhead

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory