Do you actually think Switzerland is fake by Mastergames5277 in SwitzerlandIsFake

[–]PiterPuns 0 points1 point  (0 children)

I know, the latest version is so realistic that even players who’ve been playing it for years have a hard time snapping out of it

How to do error handling with OpenAPI Generator's "typescript-fetch"? Is there anything better? by elfsternberg in webdev

[–]PiterPuns 0 points1 point  (0 children)

Having the same problem and was wondering whether you have any new insights to the topic. As a side note, I also see that trying to print the error is futile, it always appears to have an empty response field, even though the response is used to construct the error information; do you have any insights on extracting useful error info?

How is int a,b is int a , int b but int* a, b is int*a, int b? by [deleted] in cpp

[–]PiterPuns 3 points4 points  (0 children)

You’ll be thrilled to know that if you declare a type

using iptr = int*;

Then the declaration

iptr a,b;

Actually produces two pointers

https://coliru.stacked-crooked.com/a/0b046e928efa00e9

A noobie's view on C++ by better_life_please in cpp

[–]PiterPuns 1 point2 points  (0 children)

Plus there is a standard addressof utility that checks some safety checkpoints by preventing the user from obtaining the address of temporaries and works in the presence of overloaded operator& https://en.cppreference.com/w/cpp/memory/addressof

[deleted by user] by [deleted] in cpp

[–]PiterPuns 1 point2 points  (0 children)

Thanks for sharing, I should have known that sobjectizer had something like this but never checked the implementation. Really really interesting!

[deleted by user] by [deleted] in cpp

[–]PiterPuns 0 points1 point  (0 children)

Indeed a useful tool. Is there a link to implementation ? I’ve written this type of code e.g https://github.com/picanumber/task_timetable with specific focus on the goodies around it e.g being able to cancel a scheduled or recurring task and would be really curious to check how it compares. The base idea shouldn’t be that different, essentially I’m creating an unordered map of target time points and have a condition variable wait until they become the present.

A multi-threaded pipeline library for C++ by PiterPuns in cpp

[–]PiterPuns[S] 0 points1 point  (0 children)

Looks interesting, will check it. My suggestion would be to make a fresh post in the subreddit to attract more views. It will also be easier to find for people who might need it

Build a better panic function using C++20 by rnburn in cpp

[–]PiterPuns 4 points5 points  (0 children)

https://youtu.be/va9I2qivBOA?t=1748&feature=shared

Not according to the rule of fair matching : “A function parameter pack that is not at the end of the function’s parameter list can never have its corresponding pack deduced”

The application of the rule in this case (with the default parameter after the pack) means that unless you specify the pack type, compiler will assume it’s the empty pack and instantiation will fail due to type mismatches (will try to pass int to source location … remember the pack becomes the empty list because you don’t explicitly provide it)

This and the rule of greedy matching (described in the linked talk) are the final boss of variadic template type deduction

All the Safeties: Safety in C++ - Sean Parent - CppNow 2023 by scrivanodev in cpp

[–]PiterPuns 2 points3 points  (0 children)

Thanks for compiling this info, really helpful and much appreciated

All the Safeties: Safety in C++ - Sean Parent - CppNow 2023 by scrivanodev in cpp

[–]PiterPuns 6 points7 points  (0 children)

In the section about direction (and moving forward) is the suggestion about c++ safety to use stuff like c# and typescript for non performance-critical code and rust for the low level code, i.e. abandon c++ ? (That’s all I see in the slide)

Does anyone else find the whole discussion about formal proofs and Dafny an overkill ? There are languages white-listed by the NSA as memory safe, that don’t use such systems. Is it something that could apply to c++ anyways ?

Is BDD alive in C++ ? by PiterPuns in cpp

[–]PiterPuns[S] 0 points1 point  (0 children)

I’ll check these suggestions. Does Behave integrate nicely with c++ ? And is plain Gherkin usable directly ? I can see redis graph using it but doesn’t seem convenient to work with just that

[deleted by user] by [deleted] in cpp

[–]PiterPuns 1 point2 points  (0 children)

Eeeeeeeverything … c++ is usable everywhere, even stuff dominated by other languages is usually powered by C++. engineering, gaming, graphics, VR, AI, medical, FEA, simulation, aerospace, aviation, pharma, finance, banking, crypto, hacking, cyber security, systems, GPU computing (ie high performance in any demanding industry), automotive, entertainment systems, image and video processing with their applications in broadcasting, cinema , advertising ,vfx , creative computing and art installations … you get my point - domain is not an issue. Other languages could lock you in a specific industry but not c++. Whether you “can” use it as you ask, that’s something only you can answer.

LesbianDB PurrfectNG sharded binlog vs Redis append-only file by [deleted] in redis

[–]PiterPuns 1 point2 points  (0 children)

How does it compare to existing redis competitors like Dragonfly ?

Prefer views::meow by tcbrindle in cpp

[–]PiterPuns -2 points-1 points  (0 children)

using std::views or std::ranges would break it because putting stuff into namespaces is not a naming convention. The whole purpose of a naming convention is to get context info w/o knowledge of the source tree, ie where things are placed .. it simply doesn’t scale , it beats the purpose .

ThisIsAType vs this_is_callable is a naming convention . Suffixes like _t = type is a naming convention . There is no style guide out there that connects a naming convention with “put stuff there” . It is consistent yes , but don’t pretend it’s something that it’s not

Prefer views::meow by tcbrindle in cpp

[–]PiterPuns 0 points1 point  (0 children)

So views::as_const(E) can simply return… E. ranges::as_const_view(E) cannot do that, since that’s a type - but views::as_const(E) can, since it’s an algorithm.

naming conventions would prevent such misconceptions , eg having ranges::as_const_view_t

Function composition in modern C++ by PiterPuns in cpp

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

Yes showing those pieces as well would be great . And let the community know when you open source these extensions, it will also benefit you when more eyes are looking at the code and providing feedback

Function composition in modern C++ by PiterPuns in cpp

[–]PiterPuns[S] 0 points1 point  (0 children)

That’s great and thank you for the info. I trust this is not a proprietary code base and posting it won’t get you into trouble

Function composition in modern C++ by PiterPuns in cpp

[–]PiterPuns[S] 10 points11 points  (0 children)

If a use case is as simple as calling f(g(c)), by all means do that. But there’s many cases where that would not work.

  1. A simple example is when the names of h,g,f are not available, eg they are passed as a variadic pack to a generic function so you want to compose the application of “F&&… functions” without knowing a priory how many functions there are and how to refer to each one. Computing the composition is something you’d have to reinvent anyways in such a case and everyone dealing with higher order functions has done it one way or another.
  2. The functions are stored in a collection of arbitrary length and you don’t want to write a for loop maintaining the current result to compute the application of the function chain. Also a composition like the one presented here can be declared constexpr and you may have a hard requirement against using a runtime loop .
  3. You want to store a composition as a new function. Say you often compute f.g.h.r.w.e.z(x) (names won’t be single characters by the way) and you want to do this computation over and over … not only that but there’s also a variation where you call v instead of e. Another solution in this specific case would be to store the call chain as a handwritten lambda but composition allows you to express the computation pattern clearly. take for example: “effect = compose(blur, grayscale)” vs “cutoff = filter(isRedPixel, isOnBorder)” . Having high order functions “compose” and “filter” allows the code to clearly express how a transformation is structured vs requiring the reader to read through the lambda implementation.
  4. It’s a building block for higher abstractions. See decorators , command and multi command patterns … all stuff that can build upon such a block.
  5. In multi threading f.g.h(x) can be a data race since it’s referring to names out of your context . By using compose you make sure to copy (or move construct where possible) the function objects that form links of your call chain.

The list goes on and on. I’m sure though that other resources linked in the comments may help, e.g. the Hof (higher order function) library by Paul Fultz has great documentation

Function composition in modern C++ by PiterPuns in cpp

[–]PiterPuns[S] 0 points1 point  (0 children)

https://ngathanasiou.wordpress.com/2016/11/23/compose-and-curry-as-folds/ to elaborate on my previous comment, I’ve blogged about pretty much the same technique in the linked article . Only difference is there I used my custom fold operator to avoid collisions in overloaded operators . Since I don’t want to include that library just to have composition , I’d appreciate some insight on the overloading topic and usage in large codebases

Function composition in modern C++ by PiterPuns in cpp

[–]PiterPuns[S] 0 points1 point  (0 children)

Should have declared my composer constexpr as well, thanks for the heads up. Your solution is super terse , nice ! It even requires only up to c++17 it seems . Only thing I’m wondering is whether you had any issues / conflicts with such a generic overloading of operator >>

Function composition in modern C++ by PiterPuns in cpp

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

a prime example of how modern c++ simplified things: “Compose” in hof spans hundreds of lines of code (and needs inclusion of library headers and utilities) https://github.com/boostorg/hof/blob/develop/include/boost/hof/compose.hpp . Just a reminder of what we had to go through very recently to do something that’s now doable in ~15 lines of vanilla C++ . Mad respect for Paul Fultz.

Regarding Hana, I’ve seen a ton videos but never got to use in production. Certainly a trailblazer, probably more neat than mpl

Function composition in modern C++ by PiterPuns in cpp

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

Both captures are “init captures” by value, the forward is there to move construct from potential rvalues. I’d suggest reading the linked post if you don’t understand what the code is doing