HNHacker News
TopNewBestAskShowJobs

clishem

726 karma · joined January 27, 2016

submissionscomments
clishem··on Stanislav Petrov, a Soviet officer who averted nuclear war, has died
The 'winner' of the cold war?
clishem··on Std::visit is everything wrong with modern C++
Glad you enjoyed my comment then.
clishem··on Std::visit is everything wrong with modern C++
Thanks for the clarification. This article also helped. http://talesofcpp.fusionfenix.com/post-21/rant-on-the-stdexp...

In it's terminology, std::variant is a 'discriminated union' instead of a 'sum type'. Making std::variant the latter would also have had disadvantages it seems.

clishem··on Std::visit is everything wrong with modern C++
> Sum types don't just store values of different types.

That's exactly what a tagged union does. std::variant is a tagged union. I was not aware of the name 'sum type' but it's supposed to be a synonim for a tagged union. Guess not, but std::variant is not meant as what you describe[1].

[1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n454...

clishem··on Std::visit is everything wrong with modern C++
> How would you do that without making the visitor cases explicit?

See my edit.

    std::visit([](auto &&val) { 
        std::cout << typeIdxToString[typeid(val)] << val; 
    }, var);
> E.g. you would want the '+' operator to do different things for strings and numbers.

Then overload the '+' operator, no need to put all that in the visitor lambda.

clishem··on Std::visit is everything wrong with modern C++
So basically you're saying that if you want different behavior based the type of a variable passed to a function, you're going to have to write that behavior...

Then the answer is yes. We haven't advanced to the point where the compiler can guess that you want. If you can give me an actual example of when it would be an insurmountable task to do so, please let me know.

clishem··on Std::visit is everything wrong with modern C++
This blog post is not to be taken seriously in my opinion. For one thing, `printf` is obsolete in C++. This is how you should output values in a tagged union:

    std::variant<size_t, std::string> var = "test";
    std::visit([](auto &&val) { std::cout << val; }, var);
If you also want to print the name of the type of the variable, along with the value itself, well, C++ doesn't have reflection (yet). So you're going to have to write a function that takes a value and returns its type as a string, which you can already do using the typeid operator. This is basically implementing reflection yourself, it is cumberstone but doesn't require advanced template programming.

There no need for any of the madness with explicit types inside the visitor lambda, which is deemed as neccesary by the author.

Edit: here's another way to map types to strings. So no templates necessary at all for this entire problem.

    std::map<std::type_index, std::string> typeIdxToString;
    typeIdxToString[typeid(std::string)] = "string";
    typeIdxToString[typeid(int)] = "int";
    // ...
Edit2: Turns out C++ has some form of reflection after all. You can just use:

    typeid(val).name()
If your compiler supports pretty names.
clishem··on Robert Shiller says Bitcoin is the best example right now of a bubble
1. so are all other cryptocurrencies

2. see 1

3. not sure what you mean by this

clishem··on Hell is a multi-threaded C++ program (2006)
> lack of thread local storage is not an issue

We've had it since C++11. http://en.cppreference.com/w/cpp/language/storage_duration

clishem··on Show HN: The best time to visit any city
Something fishy is going on here:

https://championtraveler.com/dates/best-time-to-visit-cuba/

https://imgur.com/YlM3zda.png

But really great idea!

clishem··on Show HN: Unlimited UI design
The logo links to http://fairpixels.co/pro/index.php which gives a 404.
clishem··on Can QML become the next standard for web UI?
Betteridge's law is strong with this one.
clishem··on Schleuder: A GPG-enabled mailinglist with remailing-capabilities
Alternative software that does the same: https://fbb-git.github.io/gpg-remailer/
clishem··on If borders were open
Based on the fact that there is finite money for social welfare.
clishem··on URLs are UI
http://urlme.me/wow/URLs/Are_UI.jpg
clishem··on Stopping the Internet of Noise – A useful internet back again
I was very tired when I wrote that, my apologies.

What I meant was that IRC is still alive and kicking.

clishem··on Stopping the Internet of Noise – A useful internet back again
> Once was IRC

Seriously?

clishem··on Show HN: Cpp_Redis – C++11 Lightweight Redis client

    namespace redis = cpp_redis;
there you go.
clishem··on Block-breaking game in vim 8.0
It was forked before vim 8.0 was released and neovim doesn't try to keep its fork compatible with vim. Consequently it is not.
clishem··on Show HN: Cpp_Redis – C++11 Lightweight Redis client
This is not a silly question. Yes, using the C library from C++ is certainly possible. There would be nothing non-compliant about that, although you would need to write code that is somewhat frowned upon when writing C++ (i.e. using raw pointers all over the place). No, this is not a wrapper. It doesn't use the C library to pass queries to redis.
clishem··on Skip grep, use awk
Took me a while to understand the name.
clishem··on Show HN: A message board with anonymous, open moderation
Maybe change the rest of the CSS while you're at it.

This is not good UX http://i.imgur.com/en3lBF5.jpg

clishem··on Ask HN: In the event of a singularity, which stocks would you buy and why?
And which ones to short?
clishem··on Ways to Get Better at C++
One of the best technical books in existence (afaik).
clishem··on July 12th: Internet-Wide Day of Action to Save Net Neutrality
It's not internet-wide.

They mention the FCC as if non-US citizens are supposed to know what that is. They ask for a zip code, without asking for a country. The phone number they listed will not work anywhere but in the US. The address listed in their privacy policy does not name a country.

All this leads me to believe that the people behind this think the Internet only exists in the US, or that they are not even aware there are other countries besides the US. Don't worry, you're not the one that's stupid here.

clishem··on List of Printers Which Do or Do Not Display Tracking Dots
Do you mean FOSS printer drivers? Are you sure that would make a difference?
clishem··on July 12th: Internet-Wide Day of Action to Save Net Neutrality
It asks for my ZIP so this action is not Internet-wide.
clishem··on iPad Pro
You want to use a toy instead of a computer for web development?
clishem··on Hacker News Readers as Progressive Web Apps
Try this: http://news.ycombinator.com
clishem··on Ask HN: What do you use in your New Tab window?
about:blank
← PreviousPage 2 of 7Next →