TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A repository of modern C++ code samples curated by the community

275 点作者 edran大约 10 年前

18 条评论

sftrabbit大约 10 年前
Creator of the site here. Thanks for taking a look and I really appreciate all the feedback.<p>I wanted to provide a place for beginners to learn about modern features of C++ and a quick reference for idioms and best practices. As the disclaimer says, the existing samples all need review, so don&#x27;t take anything as gospel. If you would like to contribute please check the samples GitHub repo [0] or leave comments on the sample pages themselves.<p>A few good points that keep coming up:<p>- The Rule of Three sample especially needs a rework (it will become the Rule of Five later today).<p>- It isn&#x27;t supposed to demonstrate the best C++ formatting style, simply because that would come down to personal preference.<p>- I have opted to not use `auto` unless necessary for the sake of being explicit about types so that beginners have something to reference against. This is important regardless of ones particular preference for when `auto` should be used and it would be impossible to please everybody. I will be adding a note to the site soon.<p>- I plan to add a &quot;requirements&quot; section to the sample information which will state which version of C++ the sample depends on.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;sftrabbit&#x2F;CppSamples-Samples" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sftrabbit&#x2F;CppSamples-Samples</a>
评论 #9333731 未加载
评论 #9333896 未加载
评论 #9334709 未加载
评论 #9335883 未加载
评论 #9334070 未加载
评论 #9335558 未加载
rectang大约 10 年前
What&#x27;s the licensing of these samples?<p>Perhaps consider CC0? <a href="https:&#x2F;&#x2F;creativecommons.org&#x2F;choose&#x2F;zero" rel="nofollow">https:&#x2F;&#x2F;creativecommons.org&#x2F;choose&#x2F;zero</a> I think CC0 would allow them to be reused in any project no matter the license, without requiring attribution. Do others agree with that?<p>Regardless, best practice for a project which uses any of these samples would be to record the origin in version control, even if credit is not given in the project source code.<p>It&#x27;s really important that sample code have clean provenance, since others will be inserting it into their own projects then possibly mutating it and making it difficult to extract. Are these samples all completely original? And will there be any IP controls as far as what you accept for Github pull requests?<p>(edit: don&#x27;t try to use markdown for links.)
评论 #9333645 未加载
SCHiM大约 10 年前
Would be useful if it grows and gets a easily search able index.<p>I can&#x27;t count the number of times I couldn&#x27;t be bothered to write boiler-plate C++ to eg. strip a string [0].<p>I know that if I google the question I&#x27;ll get a stackoverflow question with the answer. A dedicated site would be an improvement in my opinion. Mostly because of over-zealous mods on SO that confuse the reality of SO with their personal vision of what is good for SO.<p>[0] <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;216823&#x2F;whats-the-best-way-to-trim-stdstring" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;216823&#x2F;whats-the-best-way...</a> There we go.
评论 #9333505 未加载
ndesaulniers大约 10 年前
I think the shared_ptr and unique_ptr examples could better show why you&#x27;d choose one over the other, and what their limitations are.
stinos大约 10 年前
Well done. Thinking of it, congratulations for being the first (afaik) to do this, should have been done a long time ago. Looked through quite a lot of the samples and none really raised my eyebrows, which doesn&#x27;t happen often for the typical &#x27;C++ tutorial&#x27; type of site. (not that I&#x27;m some kind of authority, I just write C++ almost daily for a living) Especially nice are all the links, also to articles of Meyers etc. More of the latter would be great, Sutter also did a series once which covered a lot of the basics quite well.<p>I hope this will also help with cases like: earlier on HN there was the C++ vs Rust article [0] and corresponding comment thread where one valid complaint was the author was comparing &#x27;C++ which no-one writes in production&#x27; vs Rust or something in that spirit [1]. It would be great if this site becomes an authorative source one can point to, instead of the huge amount of scattered resources there is now. Like now you have cppreference for the dry theory, cppsamples could become that for putting it in practice :]<p>[0] <a href="https:&#x2F;&#x2F;rnestler.github.io&#x2F;more-rust-compared-to-c.html" rel="nofollow">https:&#x2F;&#x2F;rnestler.github.io&#x2F;more-rust-compared-to-c.html</a> [1] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9329506" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9329506</a>
ausjke大约 10 年前
Great site and initiative indeed.<p>However can you make the indent to 2 or 3 char? 8 is too luxury in a web-browser these days.<p>Openstack has a different way to show comments and the code in parallel, the color does not match the text somehow, but it&#x27;s another way to do it.<p><a href="http:&#x2F;&#x2F;docs.openstack.org&#x2F;developer&#x2F;devstack&#x2F;stack.sh.html" rel="nofollow">http:&#x2F;&#x2F;docs.openstack.org&#x2F;developer&#x2F;devstack&#x2F;stack.sh.html</a>
AtmaScout大约 10 年前
Thanks for this, I hope to see many more examples.
gh02t大约 10 年前
This is really helpful for me, thanks!<p>I only use C++ in bursts, so while I&#x27;m at least competent enough with the basics, I usually forget how to do specific things and have to google the same few things over and over again. It looks like you already have several of the things I&#x27;m prone to forgetting, so this is really perfect! Looking forward to seeing more.
lmedinas大约 10 年前
I like it! Specially because it explains exactly what the code does in a generic way. But to me, personally, it&#x27;s far too much &quot;modern&quot; C++ or C++11 oriented, it would be nice to have with the same clean design for the &quot;old&quot; C++.<p>Any reason for not having any snippet with the &quot;new style&quot; range based for loops ?
BinaryIdiot大约 10 年前
My friend sent me this site earlier. As someone who used to code in C++ over 10 years ago and has been desperate to get back into it this site is perfect for me. Thanks for creating this and I hope it expands and grows as I&#x27;m already finding it useful :)<p>Thanks!
esaym大约 10 年前
Is there a good book &quot;modern C++&quot;, kinda like &quot;modern perl&quot; I guess?
评论 #9334312 未加载
Calms大约 10 年前
Great stuff.<p>Do you feel explicitly stating any licensing (or lack of) be a good idea for the samples?
评论 #9333603 未加载
评论 #9333595 未加载
santaclaus大约 10 年前
It would be pretty sweet to have IDE integration with something like this -- when creating a source file in Xcode or Eclipse, have a menu pop up with various curated samples of common C++ idioms.
评论 #9336535 未加载
Aqwis大约 10 年前
What&#x27;s the deal with std::experimental? Does the &quot;experimental&quot; part means they shouldn&#x27;t be used in production code?
评论 #9334173 未加载
im2w1l大约 10 年前
First: Very nice site, good job!<p>I think you should remove the bubble sort snippet. A newbie may use it verbatim without realizing there are better algorithms.<p>It may be good to give an example of RAII that protects a resource other than memory, to plant the idea of wider applicability in your reader&#x27;s head.
partisan大约 10 年前
I like the idea, but the site is unusable on mobile (iPhone 5s).
评论 #9339870 未加载
voltagex_大约 10 年前
Hoping this expands to more languages. SampleOverflow? It&#x27;d clean up the number of trivial question&#x2F;answers on SO.<p>I&#x27;d love to see some socket code on the site, at any rate.
icpmacdo大约 10 年前
Are there websites like this for Java and JS?