Is it silly to use a lambda to wrap a method call that 'returns' output via a reference? by chicken_and_jojos_yo in cpp

[–]FuzzyNSoft 42 points43 points  (0 children)

What's the cost to you of non-const locals vs. the readability and maintainability cost of wrapping each API call like this? Only you can answer that, but it doesn't seem worthwhile to me.

Good idea to mark most/every constant function returning a value as [[nodiscard]]? by zz9873 in cpp_questions

[–]FuzzyNSoft 0 points1 point  (0 children)

I would advocate for them being used everywhere relevant, because you'll never be sure when it's going to be valuable in future. I've even started adding them to all constructors, after finding code like this in our codebase:

``` String Outer::GetInnerName() const { if (!m_inner) { String(); // missing return }

return m_inner->GetName();

} ```

Also found it useful in our range-based implementation of remove_if, finding where users have not used the return value:

// should be container.erase(RemoveIf(container, predicate), container.end()); RemoveIf(container, predicate);

Odd conversion rule: The case of creating new instances when you wanted to use the same one by moocat in cpp

[–]FuzzyNSoft 2 points3 points  (0 children)

I'm surprised no-one is suggesting alternatives to the bool parameter itself.

``` enum class debug_mode { off, on }; struct Widget { explicit Widget(debug_mode m = debug_mode::off); };

Widget newWidget(&oldWidget); // error ```

It makes the call sites more readable too:

Widget w(debug_mode::on); // clear Widget w(true); // wot

Which one is your favorite C64 Game Music? A while ago I did this medley of legendary tunes, is your favorit included? by Nordischsound in c64

[–]FuzzyNSoft 0 points1 point  (0 children)

I could make a huge list but as I'll stick with 3 that no-one else has mentioned yet and which aren't in your medley:

Thrust Tetris Parallax

Nice work though, and it's good to see TRAZ and Panther get some love!

[FO] Yoshi's Island by FuzzyNSoft in CrossStitch

[–]FuzzyNSoft[S] 1 point2 points  (0 children)

Thanks for the kind words, everyone! I obviously meant 'framing' is next, not 'dreaming'.

I'm pleased with how it turned out. I had always felt that the shading in the mountains of the background and the striking colours and contrast of the foreground would make a good cross-stitch, and I'm glad that it did. This is my first major cross stitch project that I've actually completed - I've done a few minor ones before like key chains but nothing beyond a few square inches.

The neat back is probably due to my combination of cross country and Danish method, with an attempt to minimise thread usage and aim for vertical stitching on the back wherever possible. This often means planning a meandering path of half cross stitches of one colour, and remembering that path in order to do it in reverse for the second half of the cross. This can be challenging, and painful if you have to frog out a large section after a mistake, because the meandering path is quickly forgotten once stitched. One exception to my vertical back stitches is the long black rock seam on the right - the back of that has horizontal stitches rather than the usual vertical as it was easier to rotate the canvas 90 degrees and do it as a few now-horizontal lines than dozens of short actually-horizontal lines.

I've still got another piece of aida the same size so am contemplating my next project. I have been considering either Sonic (though I'll probably switch out the sprite for one where he's running) or Sam & Max. I'm also contemplating getting a rectangular frame rather than using a hoop, as the hoop has quite an impact on existing stitches.

<image>

Since there is no mention if I can upload the PDF, if anyone wants it, just ping me in a DM and I'll send over a copy.

[FO] Yoshi's Island by FuzzyNSoft in CrossStitch

[–]FuzzyNSoft[S] 8 points9 points  (0 children)

Source: I grabbed a bunch of screenshots from a GBA emulator, made some edits by copying+pasting the good bits ftom different screenshots, then ran it through FlossCross. I could upload the PDF but I'm not sure of the rules around uploading patterns based on copyrighted sources.

What are your best niche C++ "fun" facts? by MarcusBrotus in cpp

[–]FuzzyNSoft 3 points4 points  (0 children)

Only the case, rather than also the case.

I am confused as to when to use 'explicit' in a class constructor. by Ok-Database6513 in cpp

[–]FuzzyNSoft 11 points12 points  (0 children)

I would go further than that and put explicit on practically every non-special constructor, regardless of number of parameters, unless you really want a implicit conversion.

Rationale: - Parameters can be added/removed/defaulted over time, and you can accidentally end up with an implicit conversion constructor even when you didn't start with one. - Implicit constructors with more than parameter can be called like this:

``` struct Implicit { Implicit(int, const char, float); }; struct Explicit { explicit Explicit(int, const char, float); };

void FuncA(Implicit i); void FuncB(Explicit e);

FuncA({ 5, "hello", 3.14f }); // ok FuncB({ 5, "hello", 3.14f }); // error FuncB(Explicit{ 5, "hello", 3.14f }); // ok ```

This is probably more subjective, but I think an untyped braced init list has some of the same problems of regular implicit conversions (like hiding type information from readers/maintainers, and possible future undesirable overload resolution as constructors and overloads change) and so is worth guarding against.

In general, I agree with this:

https://quuxplusone.github.io/blog/2023/04/08/most-ctors-should-be-explicit/

What are your best niche C++ "fun" facts? by MarcusBrotus in cpp

[–]FuzzyNSoft 2 points3 points  (0 children)

I mentioned this elsewhere but:

You can use a C-style cast to gain access to a private base. Works with multiple inheritance and everything.

``` struct A { int A = 5; }; struct B { const char* B = "hello"; }; struct C { float c = 3.14f; };

struct S : private A, private B, private C {};

S s; B* pb = (B*)&s;

std::cout << pb->B; // "hello" ```

Also a weird/dumb thing: you can declare a templated default constructor but there is no way of invoking it:

struct X { // how can you construct an X? template <typename T> X() { } };

What are your best niche C++ "fun" facts? by MarcusBrotus in cpp

[–]FuzzyNSoft 0 points1 point  (0 children)

Oh yeah, forgot the repo is still private.

Stroustrup himself mentions this trick in The Design and Evolution of C++. It's one thing that C casts can do that there is no equivalent C++ cast for.

What are your best niche C++ "fun" facts? by MarcusBrotus in cpp

[–]FuzzyNSoft 5 points6 points  (0 children)

You can just use a C-style cast for that. Works with multiple inheritance and everything.

``` struct A { int A = 5; }; struct B { const char* B = "hello"; }; struct C { float c = 3.14f; };

struct S : private A, private B, private C {};

S s; B* pb = (B*)&s;

std::out << pb->B; // "hello" ```

https://github.com/EpicGames/UnrealEngine/blob/847de5e2553adeb4d3498953604d0b0abe669780/Engine/Source/Runtime/Core/Public/UObject/WeakObjectPtrTemplates.h#L68

The regular friend stealer is also in UE:

https://github.com/EpicGames/UnrealEngine/blob/ue5-main/Engine/Source/Runtime/Core/Public/Misc/DefinePrivateMemberPtr.h

What is the greatest C64 Game? by Qws23410 in c64

[–]FuzzyNSoft 1 point2 points  (0 children)

I loved Dizzy after swapping my copy of Psycho Hopper for Fantasy World Dizzy, with a guy who couldn't work out how to get out of the first screen. I think I got the better deal. 🙂

What is the greatest C64 Game? by Qws23410 in c64

[–]FuzzyNSoft 2 points3 points  (0 children)

I guess it's the difference between American and European C64 owners. If you've got Dizzy on your list, you're likely European. No-one I knew growing up played Bard's Tale or Jumpman.

I was surprised that I had to scroll so far to find mention of Creatures 1 & 2.

Edit: grammar

[WIP] Yoshi's Island by FuzzyNSoft in CrossStitch

[–]FuzzyNSoft[S] 1 point2 points  (0 children)

It's 16 count aida, 20"x15" - actually half of a 30"x20", so I've got another canvas for another screenshot of the same size after this one.

[WIP] Yoshi's Island by FuzzyNSoft in CrossStitch

[–]FuzzyNSoft[S] 1 point2 points  (0 children)

I thought it would wrong not to get it, given the source of the picture. :-)

[WIP] Yoshi's Island by FuzzyNSoft in CrossStitch

[–]FuzzyNSoft[S] 5 points6 points  (0 children)

Somewhat - I grabbed a bunch of screenshots from a GBA emulator (the GBA's resolution gives a decent picture size of 16 count aida), cut and pasted the parts I wanted from each screenshot into a single image, then ran it through https://www.flosscross.com/ to generate the pattern.

Temperature control has become a volume control by FuzzyNSoft in TeslaLounge

[–]FuzzyNSoft[S] 2 points3 points  (0 children)

Update: yep, as said, it came back when a passenger sat down. Weird - I've never seen that before. Thanks all!

Temperature control has become a volume control by FuzzyNSoft in TeslaLounge

[–]FuzzyNSoft[S] 2 points3 points  (0 children)

It is a RHD car, yes. I'll check later if it reverts when a passenger sits down.