TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why C++ Is Terrifying

17 pointsby uvdn7about 4 years ago

5 comments

saurikabout 4 years ago
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 未加载
ostenningabout 4 years ago
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.
dwrodriabout 4 years ago
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 未加载
thunkshift1about 4 years ago
Can someone knowledgeable break down into simple terms what the tweet means?
评论 #26839101 未加载
sischoelabout 4 years ago
With C++20 and the std::invocable concept, is there still much reason to use std::function?
评论 #26838976 未加载