←back to thread

51 points klaussilveira | 2 comments | | HN request time: 0s | source
Show context
TillE ◴[] No.45082460[source]
> VisualC++ doesn’t have its source code available

Got all the way here and had to look back up to see this post was from 2019. The MSVC standard library has been open source for several years now. https://github.com/microsoft/STL

Though to be perfectly honest, setting a breakpoint and looking at the disassembly is probably easier than reading standard library code.

replies(2): >>45083002 #>>45083530 #
tialaramex ◴[] No.45083002[source]
As STL (nominative determinism at work) points out in the r/cpp thread about this, even when that git repo didn't exist you could have gone to see how this template works because C++ has to monomorphize generics somehow and that means when you write shared_ptr<goose> your C++ compiler needs to compile the source code for shared_ptr with the T replaced by goose.

But you're correct, while I can read https://doc.rust-lang.org/src/alloc/sync.rs.html (where Rust's Arc is defined) ...

... good luck to me in https://github.com/microsoft/STL/blob/main/stl/inc/memory

There are tricks to cope with C++ macros not being hygienic, layered on top of tricks to cope with the fact C++ doesn't have ZSTs, tricks to reduce redundancy in writing all this out for related types, and hacks to improve compiler diagnostics when you do something especially stupid. Do its maintainers learn to read like this? I guess so, as it's Open Source.

replies(1): >>45083532 #
1. chuckadams ◴[] No.45083532[source]
It also helps that the Rust version is lavishly documented with examples, and the C++ version has barely any comments at all.
replies(1): >>45083659 #
2. tialaramex ◴[] No.45083659[source]
Fair, although slightly cheating because some of the examples in the Rust are literally documentation & that C++ isn't doing the same thing

    /// This is inline markdown documentation in Rust source,