HNHacker News
TopNewBestAskShowJobs

jmax01

24 karma · joined October 3, 2021

submissionscomments
jmax01··on [dead]
Example Code: struct Shape { void draw(); int area(int x, int y); };

make_trait(Shape, draw, area);

int main() { auto circle = Circle(); auto square = Square(); // NOTE: all of this is strictly checked, so if you are creating // a trait out of a Object, the object MUST implement all the trait functions auto t0 = trait<Shape>::make(&circle); t0.draw();

    auto t1 = trait<Shape>::make(&square);
    t1.draw();

    // Another thing to be kept in mind is trait<T> is just like a View
    // It DOES NOT OWN anything, so you are the one making sure the data
    // pointer is valid
  
    auto array = std::array{t1, t0};
    for (auto& shape : array) {
        std::cout << shape.area(2, 3) << std::endl;
    }    
}
jmax01··on Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20
Yes thats a typo
jmax01··on Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20
Well thats how the current C++ compilers/standard is. There is a limit to what a header/library can do
jmax01··on Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20
I get it, the Rust enum system is such a connivence, but well the secret sauce in the readme is what the "official people" say....
jmax01··on Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20
Hey, I am the author of this, I made this mostly for the purpose of experimenting and playing around and trying out things rather than actually using this for production projects. Making a proper compile time checker is pretty complicated(possibly impossible) without actually getting into the compiler, this just intends emulate that behavior to some extent and have a similar interface. "educational purposes" -> well kinda, I had some free time and had an interesting idea perhaps