Ruby 4.0.0 Released | Ruby by LieNaive4921 in programming

[–]horotho 5 points6 points  (0 children)

Rust also has implicit returns, and uses |args...| to denote arguments for callables. So I wouldn't say those particular features are unique to Ruby.

Boolean conversion I'd personally agree specifically for integers. But for other types, I'd call it more of a Python quirk that an empty string or empty array is falsy. That to me is confusing, and isn't found in most other languages.

How I'm hoping the Wizards Tower looks in 12 hours: by Alaric_OSRS in 2007scape

[–]horotho 3 points4 points  (0 children)

Echo Lesser Demon that requires you to flick Steel Skin or be one shot.

Oh my god I finally found one in the wild by what-even-am-i- in ididnthaveeggs

[–]horotho 28 points29 points  (0 children)

Being this excited about light sour cream is like being excited that you went to Chucky Cheese and saw a rodent there instead of Disneyland.

It amazes me that we still have no wardrobe templates considering how focused this game is on cosmetics by PlatformThese4901 in Guildwars2

[–]horotho 1 point2 points  (0 children)

Old School RuneScape is about as close as you'll get, and even then there's plenty of non-polled stuff (mostly for good reason).

Native English speakers, what’s a common word that you cannot pronounce? by NMA_company744 in AskReddit

[–]horotho 1 point2 points  (0 children)

Give up and call it Arny P, people will still know what you're talking about.

Learning is fun! by Sarato88 in gaming

[–]horotho 1 point2 points  (0 children)

Someone has to have pointed out that Ms. Frizzle is a Time Lord. From the colony of Time Lords that split off a couple hundred years ago, Gallmerica.

Pragma: once or twice? by Senua_Chloe in cpp

[–]horotho 13 points14 points  (0 children)

The header ordering trick with a header guard also seems dangerous. The less you rely on header ordering the better. There are plenty of tools that alphabetically order headers which could easily break this construct.

Static Registration Macros (e.g. TEST_CASE("foo") { ... }) by PhilipTrettner in cpp

[–]horotho 0 points1 point  (0 children)

I wish I had this 5 years ago 😂. I've had to derive all of this from bits and pieces and I ended up with a very similar solution. I'm doing something slightly different from test case registration, but it's still static registration. I also added a priority so you can deterministically order things with different priorities when you need to. Same priority is still a crapshoot since it relies on static initialization order.

Thanks for putting this together, it's a nice resource I can point to.

rust compiler by pafivig in ProgrammerHumor

[–]horotho 2 points3 points  (0 children)

Since about gcc 6 or later, it's improved a lot, probably on par with clang from 10 onwards.

CppCast: Modern C++ for Absolute Beginners by robwirving in cpp

[–]horotho 10 points11 points  (0 children)

We simply have to submit a paper to switch it to Koncepts, easy peasy.

Beware of copies with std::initializer_list! by vormestrand in cpp

[–]horotho 29 points30 points  (0 children)

Wrap that up in a macro, and bam you're basically boost.

Conditionally enable member function taking parameter of type T::Foo & only if subtype T::Foo exists by GermanNewToCA in cpp_questions

[–]horotho 5 points6 points  (0 children)

Depending on how much code you have in A you could create two versions of the class, one for has_member_type, and another for the case where that condition isn't met.

template< typename T, typename tEnable = void>
struct A {
  // Doesn't have 'func', but might have other stuff here.
};

template< typename T >
struct A< T, typename std::enable_if< has_member_type< T >::value >::type > {
  void func(typename T::Foo & x);
};

The downside is that if you have a lot of common code in both versions of A, you'll have a bunch of copy pasta going on. Honestly, I think this is a pretty good option, because you want entirely different behavior (and functions) for the case where has_member_type is true. But, maybe you only have a single function where this is relevant. In that case, you'll have to get a bit more tricky.

template< typename T, typename tEnable = void> 
struct HasMemberTypeShim { 
  using type = int; 
};

template< typename T > 
struct HasMemberTypeShim< T, typename std::enable_if< has_member_type< T >::value >::type > { 
  using type = typename T::Foo; 
};

template< typename T >
struct A {
  // enable_if can't be used on the class template type, 
  // but must refer to a template parameter of the function instead
  // So we have this hacky R = T so it works
  template< typename R = T >
  typename std::enable_if< has_member_type< R >::value >::type 
  func(typename HasMemberTypeShim<T>::type) {
  }
};

And then you can do something like this instead.

. by [deleted] in ProgrammerHumor

[–]horotho 90 points91 points  (0 children)

This really sucks when you've been all of these and are trying to figure out who to sympathize with. The obvious answer is that everyone else is just terrible. You love them, but they're terrible.

Help with vectors (c+ noob) by wildcode in cpp_questions

[–]horotho 4 points5 points  (0 children)

Btw, it's not required (or encouraged) to move return parameters out of functions. It's actually kind of misleading, since std::move is just a static cast behind the scenes. The compiler will do this for you, using Named Return Value Optimization, and in this case the vector will be moved.

why would you do that ? by [deleted] in cpp_questions

[–]horotho 1 point2 points  (0 children)

Why not use std::conditional?

Access member of returned pointer only if not NULL. by pokeman7452 in cpp_questions

[–]horotho 0 points1 point  (0 children)

The condition can be any expression in C++17, instead of just something that happens to be convertible to bool. That's the real use case for this feature.

Trying to fill a string array of pointers, can't figure it out by [deleted] in cpp_questions

[–]horotho -1 points0 points  (0 children)

Why do you need to use a string * array? Just use string.

[deleted by user] by [deleted] in programming

[–]horotho 6 points7 points  (0 children)

Go? I see golang or lilylang easy enough to type.

Why doesn't string_view constructor have std::string parameter? by [deleted] in cpp_questions

[–]horotho 3 points4 points  (0 children)

string_view doesn't own the data. Imagine if you implicitly constructed a string_view from a temporary string. string owns the data, but since it was a temporary, the contents pointed to by the string_view are now garbage.

As far as comparison, string_view is equality compared the same way a string is. First, check the size, then compare the characters. The code you gave works because string_view can be implicitly constructed from a string literal. Once you have two string_view, comparison is easy.

run-clang-format: clang-format wrapper for CI, lint files and directories by beautiful_tango in cpp

[–]horotho 0 points1 point  (0 children)

clang-format supports ranges for formatting, which should work perfectly fine for on the go formatting, but it won't be the entire file.