
MSVC's implementation of the C++ Standard Library - AlexeyBrin
https://github.com/microsoft/STL
======
nurettin
I would like to stop here and thank one of the microsoft STL contributors
Stephan T. Lavavej[1] for all the work he has done on maintaining his own
MinGW repository for many many years, keeping his hand compiled gcc, SDL and
boost versions up to date.

1\. [https://nuwen.net/stl.html](https://nuwen.net/stl.html)

~~~
StephanTLavavej
You’re welcome! My MinGW distro is due for an update, which I should hopefully
have time for soon.

~~~
nurettin
It is a bit embarrassing to admit that I've been a fan of your works since
early 2000s. Learned sockets from libnuwen.

[https://github.com/nurettin/libnuwen](https://github.com/nurettin/libnuwen)

~~~
StephanTLavavej
Wow, I didn’t know anyone followed my personal library (when I was still
learning the language)! Glad it helped. Cool to meet a true fan :-)

------
TimTheTinker
These kinds of announcements from Microsoft still boggle my mind a little.

It seems only a little while ago that I heard stories of a friend’s high
school programming teacher, who received threats from Microsoft’s legal
department for emailing them a patch to fix a crash in Windows 95.

~~~
de_watcher
More than half of it is templates that you can't hide just because of the
nature of templates.

It's still the same Microsoft.

~~~
pjmlp
I prefer the same old Microsoft as the FAANG.

------
self_awareness
I'm not sure you've noticed, but one of the core authors of this STL
implementation -- Stephan T. Lavavej -- has exactly the initials of the
project he's working on: STL. This means he's perfect for this job :)

~~~
hybrids
[https://en.wikipedia.org/wiki/Aptronym](https://en.wikipedia.org/wiki/Aptronym)

~~~
0-_-0
> Jaime Sin who in 1976 was made a cardinal by Pope Paul VI, thus becoming
> known as "Cardinal Sin"

------
md224
I'm not well-versed in C++, so I'm a bit confused about the difference between
the C++ Standard Library and the Standard Template Library (STL). Wikipedia
tells me that they're related but technically separate things, yet this GitHub
page says:

> This is the official repository for Microsoft's implementation of the C++
> Standard Library (also known as the STL)

and appears to use the two terms interchangeably. Is this the C++ Standard
Library or the STL?

~~~
percentcer
[https://stackoverflow.com/questions/5205491/whats-the-
differ...](https://stackoverflow.com/questions/5205491/whats-the-difference-
between-stl-and-c-standard-library) this is a pretty solid answer to your
question

~~~
md224
Duh, I knew I should've googled first. That definitely clears it up, thanks!

------
ridiculous_fish
The implementation of std::regex appears to be NFA based [1] which is
surprising because backreferences are part of the standard.

How are backreferences implemented here?

1:
[https://github.com/microsoft/STL/blob/master/stl/inc/regex](https://github.com/microsoft/STL/blob/master/stl/inc/regex)

~~~
asdfasgasdgasdg
I think you're thinking of DFAs, which don't support backreferences. NFAs do.
Right?

~~~
ridiculous_fish
Maybe? But in theory any NFA can be reduced to a DFA through powerset
construction, so there must be something else going on.

~~~
wahern
That's only for regular languages. Backreferences aren't regular.

~~~
ridiculous_fish
Yes, hence my question about using NFAs for std::regex!

------
bla3
Cool! Are you going to accept patches to port this to other operating systems?
It would be cool if `clang -stdlib=msvc` joined -stdlib=libc++ and
-stdlib=libstdc++.

~~~
jfultz
I'm at CppCon and attended the talk today where Microsoft announced this to
the CppCon attendees. The folks speaking made it clear that they do intend to
accept pull requests, and that they're positive about it being used outside of
the VC++ environment under the appropriate license (Apache 2 with LLVM
Exception).

~~~
lsllc
What's the LLVM Exception? (asking for a friend ...)

~~~
wyldfire
From
[https://llvm.org/foundation/relicensing/LICENSE.txt](https://llvm.org/foundation/relicensing/LICENSE.txt)

    
    
        --- LLVM Exceptions to the Apache 2.0 License ----
    
        As an exception, if, as a result of your compiling your source code, portions
        of this Software are embedded into an Object form of such source code, you
        may redistribute such embedded portions in such Object form without complying
        with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
        
        In addition, if you combine or link compiled forms of this Software with
        software that is licensed under the GPLv2 ("Combined Software") and if a
        court of competent jurisdiction determines that the patent provision (Section
        3), the indemnity provision (Section 9) or other Section of the License
        conflicts with the conditions of the GPLv2, you may retroactively and
        prospectively choose to deem waived or otherwise exclude such Section(s) of
        the License, but only in their entirety and only with respect to the Combined
        Software.

~~~
corysama
Thanks!

Now, can anyone ELI5 the high-level goal of this exception? At a glance it
looks like GPL2 folks are still not happy with the patent provisions of Apache
2.0 and this is added to appease them.

~~~
jcranmer
There's two pieces to the exception.

The first piece is standard for compilers, and essentially says "our compiler
linking in bits of this code into your code doesn't count." It means the
license matters if you're modifying the compiler and support libraries
yourself, but not if you're merely using the compiler.

The second piece revolves around the concerns of mixing licenses: Apache 2 and
*GPLv3 are happy in combination, but that's because of some explicit
compatibility text in GPLv3; this extends the compatibility text to GPLv2.

------
xvilka
There is no reason to use MSVC when clang-cl[1] exists. Both Google and
Mozilla build their browsers for Windows platform for more than a year without
using MSVC. So it is a pretty solid platform and ready for production.

[1]
[https://clang.llvm.org/docs/MSVCCompatibility.html](https://clang.llvm.org/docs/MSVCCompatibility.html)

~~~
StephanTLavavej
As barchar (my coworker on the STL team) mentioned, not only does Clang use
MSVC’s STL on Windows, but also the support is from both Clang and Microsoft.
We test MSVC’s STL with Clang as a first-class citizen, and have shipped
features active for Clang before they were active for C1XX (MSVC’s compiler
front-end), notably Class Template Argument Deduction.

Clang is a great compiler! We think it’s extra great with our STL. We added
Clang/LLVM to the VS installer to make using it easier.

~~~
jcelerier
> not only does Clang use MSVC’s STL on Windows,

You can use libc++ nowadays. Works good enough for me.

~~~
ksherlock
std::filesystem? std::error_code?

------
pranith
Microsoft has come a long way lately when it comes to open source. Apple seems
to be the only major company that is still not an enthusiastic participant.

~~~
kccqzy
Apple wrote and open sourced their C++ compiler (clang) and C++ standard
library (libc++), both part of the LLVM project, years before Microsoft did.
In fact it was more than a decade ago in 2007 that Apple open-sourced clang,
and now widely adopted by the industry. Sure Apple's participation in open
sourcing may not be "enthusiastic" with huge "️Heart Open Source" billboards
but it gets real job done and has real positive impact.

~~~
oblio
Now if only you could run GPL software on the largest platform Apple sells
products for...

------
saagarjha
Ooh, nice! It’s always fun to look at alternative STL implementations to see
how a class is implemented.

------
ezoe
Due to its nature of C++ templates, MSVC STL source code was practically
available to anybody. I think in theory, I could get hand on free of charge
version of MSVC without agreeing the MS EULA then extract the archive, again
without agreeing the MS UELA, and peak the source code.

In reality, I don't bother to do that and whenever I teach C++, I ignore MSVC
and its STL. I'm willing to teach but Nooo, it's MS who prohibit me to do so.

Now I can't use that excuse anymore.

------
skissane
I wish they'd post the UCRT source on GitHub too.

(Yes I know it can be found in the SDK, but having it as a repo on GitHub
would just be so much more convenient.)

------
mhd
Does this still need

    
    
        #pragma warning(disable : 4786)
    
    ?

~~~
billyoneal
We are unaware of any such bugs requiring such a suppression; please create a
self contained repro and file an issue.

~~~
StephanTLavavej
That’s the symbol truncation warning. IIRC, the suppression is no longer
necessary because the compiler removed the warning completely.

------
userbinator
The MSVC library has always been "source available" with Visual Studio, but I
guess MS thought that they're very unlikely to actually make a profit from
it[1] so they're giving it a permissive license instead.

[1] The "new MS" seems to delight a lot of people, but IMHO it's not all
great; I'd much rather they not be "shedding" all this open-source stuff and
kept selling software, if it meant they wouldn't stuff telemetry in everything
they touch.

~~~
muststopmyths
Actually, the c++ lib has never been available to my recollection (only the
base CRT). And they don't even ship the CRT with the compiler any more.

~~~
puetzk
> And they don't even ship the CRT with the compiler any more

Just in case you/any other reader didn't know: That's just because they don't
consider the ucrt compiler-version-specific anymore, it's distribution
(binaries and source) moved into the windows SDK, E.g. Windows
Kits\10\Source\10.0.17763.0\ucrt. The vcruntime is still with MSVC.

But this source never included the STL.

~~~
userbinator
_But this source never included the STL._

You mean things like vector, map, etc. ? The source for those is already in
the header files.

~~~
Rusky
They mean the entire C++ standard library. There's plenty of non-header code
in there.

~~~
StephanTLavavej
The separately compiled parts of the C++ Standard Library have shipped in VS
installations for many years (look for xrngdev.cpp in a subdirectory typically
named crt/src, that should be distinctive enough). This was intended for
debugging purposes, covered by the VS EULA as always. These parts weren’t
standalone-buildable and we occasionally forgot to ship a file or two, but we
always tried to make it all source-readable.

Now, being open source enables much more.

------
kangulis
Standard library of Cpp uses templates extensively. So both terms are used
interchangeably.

------
voldacar
Ew that's a lot of preprocessor usage.

~~~
StephanTLavavej
We really don’t like the preprocessor, but it is currently necessary for many
things, especially supporting different architectures, compilers, and Standard
version modes. We regularly purge our implementation of no-longer-necessary
macros, even when it breaks (non-Standard) code, as we recently did with
`_NOEXCEPT`, and we look forward to removing even more.

Please file an issue if you encounter macros that don’t appear to be
necessary.

------
muststopmyths
I was looking for this a couple of months ago but I couldn't find it in the
CRT source. I don't see any tags indicating compiler version releases, so it's
a bit useless for debugging purposes (which is the main use I would have for
it).

CRT source really should also be also in an easy to find place instead of
tucked away in the Windows SDK. But I've given up expecting any kind of actual
developer consideration from the new Microsoft.

~~~
Rusky
This is a separate layer from the CRT source, which is why you didn't find it
there. It's maintained separately, versioned separately, and deployed
separately.

This also doesn't actually appear to _have_ any commits corresponding to any
released compiler versions- commit history only goes back a couple of weeks. I
suspect they'll show up once an actual release has shipped out of this
repository.

~~~
StephanTLavavej
Our commit history is stretched across multiple Microsoft-internal source
control systems. In my career (2007+ in MSVC), that’s Source Depot, two
databases of Team Foundation Server, and currently Git in Azure DevOps.

Unfortunately, we will not be making the history prior to the GitHub “Initial
commit” public. It would be a huge amount of work, would bloat the git repo,
and would be of little utility. (We occasionally have to perform programmer-
archaeology, but rarely more than a year, and usually it’s only something that
the developer who made the change can do due to personal memories.)

Consider this a fresh start. We will figure out a way to tag commits
corresponding to shipped releases.

------
choppaface
Any color on why the choice of CMake for build? Versus bazel or open-sourcing
Microsoft’s tool? Something like bazel remote builds is an absolute game
changer for large C++ projects (especially versus CMake).

(re "We're working on a CMake build system... Until that's done, we're keeping
our legacy build system around in the stl/msbuild subdirectory. (We're keeping
those files in this repo, even though they're unusable outside of Microsoft,
because they need to be updated whenever source files are
added/renamed/deleted. ")

~~~
sebazzz
If the Microsoft tool you are referring to is MSBuild, that one is already
open source.

~~~
pjc50
Is it? Finally an opportunity to understand how the damn thing works.

~~~
ygra
[https://github.com/Microsoft/msbuild](https://github.com/Microsoft/msbuild)

It's also fairly well documented: [https://docs.microsoft.com/en-
us/visualstudio/msbuild/msbuil...](https://docs.microsoft.com/en-
us/visualstudio/msbuild/msbuild)

------
harry8
They want you to contribute but you have to assign microsoft your copyright
and give them a guarantee in case anyone sues microsoft over your work.
(People sue without merit literally all the time and legal fees are bankruptcy
material for any individual).

No, flipping, thanks.

Surely microsoft can, you know, pay you for the copyright if they want own it
when they decide to merge your work? Or just take it on the same license. And
as far as providing legal guarantees for microsoft? Yeah that's gonna be a no
from any sane individual. Perhaps a big company like google might agree to
those terms but also, perhaps not.

So no they don't want you to contribute, at all, or they'd do it right.

This looks quite disappointing. But as noted elsewhere you can read some
source, or fork and refuse to contribute back I guess... But why?

~~~
otterley
> you have to assign microsoft your copyright

No, you don't. You have to provide Microsoft (and anyone else, for that
matter) a license to use your contribution per the CLA, but you still own your
work. See section 5(a), [https://opensource.microsoft.com/pdf/microsoft-
contribution-...](https://opensource.microsoft.com/pdf/microsoft-contribution-
license-agreement.pdf).

All open-source licenses effectively require this; otherwise, by default,
nobody would have a right to copy or use your contribution.

> give them a guarantee in case anyone sues microsoft over your work

I don't see an indemnification clause in the CLA. Which language are you
referring to?

> (People sue without merit literally all the time and legal fees are
> bankruptcy material for any individual)

If they had even a shred of plausible belief, the estate of Elvis Presley
could sue you tomorrow for defecating on a sofa at Graceland and potentially
bankrupt you, even if you've never visited. What's your point?

~~~
harry8
Release your patch on the same license as the project. The End. Everyone is
granted a license to the patch under that license. Nobody can take your code
and re-license under a non-compatible license.

"a. Copyright License. You grant Microsoft, and those who receive the
Submission directly or indirectly from Microsoft, a perpetual, worldwide, non-
exclusive, royalty-free, irrevocable license in the Submission to reproduce,
prepare derivative works of, publicly display, publicly perform, and
distribute the Submission and such derivative works, and to sublicense any or
all of the foregoing rights to third parties. "

The project has a license, just use it.

~~~
spookthesunset
You realize most FSF projects have similar copyright assignments, right?

~~~
harry8
I have never been asked for a copyright assignment by the FSF for a patch.
Maybe that happens and if and when it does I'd talk about that too.

[https://lwn.net/Articles/359013/](https://lwn.net/Articles/359013/)

This is hardly a dangerous, radical criticism that is novel and needs to be
fought on all fronts...

~~~
froydnj
How big and/or complicated have your patches been? Copyright assignment is not
necessary for not-legally significant changes:
[https://www.gnu.org/prep/maintain/maintain.html#Legally-
Sign...](https://www.gnu.org/prep/maintain/maintain.html#Legally-Significant)

Copyright assignment has long been used as an argument of why not to
contribute to FSF projects, and is arguably one of the reasons that Clang/LLVM
were able to garner contributions from a much broader set of folks.

