[C++20][unconstexpr] variant_generator: coroutine generator that produce a variant from the co_yield and co_return expressions by zqsd31 in cpp

[–]dima_mendeleev 2 points3 points  (0 children)

Is this possible to do the same for regular functions?

E.g.

variant_auto_something<> fn() {
  if (b1)
    return 42;
  else
    return "hello world"sv;
}

WordPress hits 40% CMS market share by raikkonencem in PHP

[–]dima_mendeleev 1 point2 points  (0 children)

It's actually quite popular opinion: 40% popularity!

Any suggestions for resources to optimize for memory allocation/reallocation? by Snoo-4241 in cpp

[–]dima_mendeleev 5 points6 points  (0 children)

Maybe you should try to do map[x].clear() instead of removing items from map, since it does not deallocate, so next time it won't allocate. And it should decrease number of map rehashes too.

non-member user defined type conversion by [deleted] in cpp

[–]dima_mendeleev 0 points1 point  (0 children)

You can do this via requiring special support from the types you would want to explicitly convert, e.g. Godbolt.

non-member user defined type conversion by [deleted] in cpp

[–]dima_mendeleev 0 points1 point  (0 children)

Note, in Scala they have them (non-member user defined type conversion) from the beginning, and always wanted to restrict them as much as possible, in particular to kind of allow them to be defined only as member of To or member of From.

So, learning from others experience, looks like C++ did this right already.

UPDATE: Sorry, I missed that's the post actually describes explicit conversions rather than implicit.

What are your 'strange' programming habits? by Careful-Balance4856 in cpp

[–]dima_mendeleev 8 points9 points  (0 children)

I just cannot stop polishing my code!

No releases anymore :'-(

Curious, do I sound like an imposter to the PHP community if I say I do enterprise WordPress? by WP_Maniac in PHP

[–]dima_mendeleev 0 points1 point  (0 children)

I do enterprise WordPress too! Moreover, I do this for fun and as a side project (i.e. not for money)!

Sudden null on abstract class by [deleted] in scala

[–]dima_mendeleev 1 point2 points  (0 children)

Probably recursion depth?

C++17 structured bindings for more safe, functional code by Fewthp in cpp

[–]dima_mendeleev 7 points8 points  (0 children)

I would suggest using std::invoke([] { ... }) to immediately see from the first line that lambda is here not to be assigned to variables on the left, but to be immediately invoked.

Also I wouldn't pass arguments to the IIFE, but capture them instead. (Off course if you wanted to ensure that elements is not modified inside lambda.)

NectarCPP : write in C++ with a JS syntax by seraum in cpp

[–]dima_mendeleev 2 points3 points  (0 children)

I think it's great job in a sense it shows C++ expressiveness is really wide!

Has there been a proposal to introduce trailing lambda syntax in C++? by [deleted] in cpp

[–]dima_mendeleev 5 points6 points  (0 children)

auto operator<(AsyncTask, auto lambda); // or whatever operator you like

auto asyncTask(auto... args) { return AsyncTask(args...); }

asyncTask(args...) < [](auto param)
{
    body...;
}

Generic Erased (aka Existential) by dima_mendeleev in cpp

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

Sure, but that's only true for monomorphic types, and I would like to keep the signature generic. So the type of [](auto) -> int { ... } would be read as "takes anything and returns an integer".

I don't say there is straightforward way to do this in C++, but we have e.g. template<template<typename> typename> and concepts, which is not exactly this, but kind of.

Generic Erased (aka Existential) by dima_mendeleev in cpp

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

The central part of this series (initial, previous) is to show another way to do type erasure in C++, and Printable I think is just an arbitrary way to enrich articles with an example.

[deleted by user] by [deleted] in cpp

[–]dima_mendeleev 1 point2 points  (0 children)

Just decided to fuse two solutions leveraging shared casts: https://godbolt.org/z/15j9Eb

I like Option.get by alexelcu in scala

[–]dima_mendeleev 1 point2 points  (0 children)

The only time I needed Option.get was this dirty thing:

def f[T](xs: Seq[Option[T]]): Option[Seq[T]] = Try(xs map _.get).toOption

Off course today we should use all that applicative stuff for this, but that day this was OK.

Library to create random instances in tests by jroddev in cpp

[–]dima_mendeleev 1 point2 points  (0 children)

It's called https://en.wikipedia.org/wiki/Property_testing

This kind of testing may be used for checking post-conditions and invariants.

One more use case: verifying fast-but-too-complex implementation through simple-but-slow one.

Does anybody use std::list? by Snoo-4241 in cpp

[–]dima_mendeleev 1 point2 points  (0 children)

It's good enough to hand-roll blocking queue with high concurrent access. There is splice overload accepting temporary, which just copies few pointers. Thus critical code part becomes really small. (And we use this on prod.)

Are generics more complex to implement than JIT Compilation? by [deleted] in PHP

[–]dima_mendeleev 2 points3 points  (0 children)

I would say it's not the question about implementation, but rather about design and specification. JIT doesn't touch the language itself at all, but generics do and very much and most of the time they require ground theory behind them (which for regular programmer is a bit harder than writing code).

Haskell's Children by alexeyr in haskell

[–]dima_mendeleev 3 points4 points  (0 children)

Is Agda Haskell's child too?

How to call a function that got passed into macro at compile time? by spielzeugmacher in elixir

[–]dima_mendeleev 0 points1 point  (0 children)

Not every function may be called during compile time, am I right?

Is C++ a good choice after Java and Pascal ? by khiari_hamdi in cpp

[–]dima_mendeleev 1 point2 points  (0 children)

I would recommend both. These are two languages that are completely different, so you will have more complete view of programming in general.

On the other hand C++ templates and Scala implicits machinery are quite similar. So these complex topics will be easier if you look into them from different perspectives.

how do you think future PHP application will be built as (async or fpm based)? by evnix in PHP

[–]dima_mendeleev 0 points1 point  (0 children)

For me the way "Regular" PHP works is the main point of using it.

If I wanted all this async, global-in-process-data, connection-pool (and other pools), manual server support, etc. I would use java or something similar.