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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Why C++ Is Terrifying

17 点作者 uvdn7大约 4 年前

5 条评论

saurik大约 4 年前
I find it way more annoying that std::function&#x27;s type erasure--but insistence that it should be copyable--means it isn&#x27;t able to commit to being movable, and so then simply <i>can&#x27;t</i> store move-only functions; in practice I simply <i>never</i> want to copy an std::function, yet the type is seemingly crippled to offer that ability :&#x2F;. Between this issue and how it tends to require memory allocation even in cases of bounded scope, I honestly just find std::function only useful in trivial &quot;toy&quot; code (or where I am going out of my way to use STL for some silly reason)... I have a few type-erasing function wrappers of my own that I use in various projects, and I do live demos for the intro CS classes I help teach wherein I quickly type out new rather-fully-featured replacements, showing the iterative implementation as you need new functionality.
评论 #26839048 未加载
ostenning大约 4 年前
Aside from writing C++ back in my graduate role after university, I’ve avoided C++ like the plague. Glad there are alternatives to it today.
dwrodri大约 4 年前
Since the HN username matches the twitter name, I&#x27;ll bite: Is it the case that a raw function pointer is always trivially copyable?<p>I&#x27;m not super familiar with C++&#x27;s memory model, especially since they have deprecated the notion of POD and replaced it with trivially constructable.<p>My rudimentary thought process is that you can&#x27;t just &quot;move&quot; raw functions because there is probably some assumptions made that a C++ function&#x27;s call-site isn&#x27;t going to move around if it isn&#x27;t owned by an object. Otherwise, the runtime would have to deduce the location of the function call every time.<p>Well, on second thought, <i>is</i> there any reason why an int function ptr should be any different from an int ptr?<p>Asking as someone who has been writing C++ on-and-off for a few years for games, school, etc. but never professionally.
评论 #26839150 未加载
评论 #26838229 未加载
评论 #26838307 未加载
评论 #26839071 未加载
thunkshift1大约 4 年前
Can someone knowledgeable break down into simple terms what the tweet means?
评论 #26839101 未加载
sischoel大约 4 年前
With C++20 and the std::invocable concept, is there still much reason to use std::function?
评论 #26838976 未加载