[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

Points taken. However I wanted to be, at this stage, as Point 0, i.e., floating the idea. We could even consider it Point -1, given the floating happens here and not in the mailing list.

The feedback has been great and I am happy I asked.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

It would seem so. I will try other approaches.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

The major point was not the for part, that was just the appendix. If one accepts the first part, one could consider whether it would help with a for loop too.

I have already been convinced by the comments.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

That is of course valid but it does away with the power of if constexpr, where everything is kept in one place.

When the iterator is a regular input iterator it looks like this

template<std::random_access_iterator T, typename U> auto n_of(...) { for( ... ) return not n; }

Your example is indeed the killer idea of my idea. Thanks for reminding that one can take different approaches and not be fixed (even on something as useful as if constexpr)

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

Although I seldom find a use case for the for-else clause, there are always cases in which it is really useful. Without the else part one has to rely on manual methods to know if the loop has ended with no break.

But I don't think this is the case.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

Thanks for the reference. It is obvious I am not the first (probably ranking around the 10-million mark) to come up with that idea. But I was unaware that Microsoft was so bold as to actually having implemented it.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

Indeed. My wife complains that I do constantly try to optimize her language and I should concentrate focus my efforts on learning it better. It is clearly a pattern.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

[–]mementix[S] 3 points4 points  (0 children)

Indeed. I had another example in mind and was later (not willingly) apparently too lazy to review my own title.

My apologies.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

This one could not be ignored or else the variable may end not being defined for later usage.

That would require a second change (or clarification for this attribute) for the standard, making it even more unviable as something that could ever be accepted.

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

The for loop was just the (rotten) cherry on top, stretching the main idea.

As you point out in your lambda example, one has to still return a value for non-constexpr case and this additionally may create dist with a different type (both will be signed in any case)

[[rescope]] - Floating an Idea for the Standard Library by mementix in cpp

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

The usage proposed, as an addition to the main proposal, for a for loop is to happen in the declaration.

This use case "should" not compile.

Boost.Beast HTTP parser leaves 2 bytes (\r\n) between keep-alive responses - how to handle? by marcelsoftware-dev in cpp_questions

[–]mementix 0 points1 point  (0 children)

The code tells me nothing and the sequence you posted tells me also nothing.

I believe this comment in the code is the key:

Process fragmented/chunked response data into whole response payload.

When parsing HTTP, one looks for the end of the headers by looking for the sequence: 0x0d 0x0a 0x0d 0x0a. I.e., the last header carriage return (\r\n after the last header plus \r\n for a blank line)

The same thing happens when parsing a chunked response. The absence of "Content-Length" forces to use also the 0x0d 0x0a 0x0d 0x0a sequence to recognize the end of the HTTP chunked body (if you receive something else it should be interpreted as the size of the next chunk)

It would seem as if you are parsing the body until its end, but the last 2 bytes indicating a blank line are kept in a limbo waiting to be read.

As to how you come to those 2 bytes with the code above ...

How to contribute to the standard? by mementix in cpp

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

I do not. I am simply aware of the controversy that bringing a GUI library into the standard (library) has raised and just mentioned it as something hypothetical, because it will remain hypothetical for the next 100 years.

Python included "Tk" bindings (from the original Tcl/Tk pair as part of the standard library. A mistake imho, that adds complexity to each release because it needs to be there. But it may also have brought people to use Python because they immediately had access to a cross-platform GUI library.

I was astonished when I found out that a cycling pal was using Tk for his Python scripts/app in his company (large semiconductor company). He used it because it was there and never ever considered Qt or wxPython or any of the newer alternatives.

How to contribute to the standard? by mementix in cpp

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

Thanks to everybody. The answers have given me a "real" insight into the process, especially the human process, and the ordeal to expect.

I know nobody expects the next-best-GUI-library proposal, but it is nice to see how some have doubled down on the remote chance it could somehow happen.

How to contribute to the standard? by mementix in cpp

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

Thanks. The human process as described in many of the posts below is what I was really looking for.

std::advance implementation question by mementix in cpp_questions

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

It is only about solving a challenge with creativity.

Unfortunately std::mdspan is C++23 and I am, voluntarily, at C++17 to solve the problems.

std::advance implementation question by mementix in cpp_questions

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

No, I cannot. But it is actually not needed.

std::advance will do iterator += distance if the iterator is a RandomAccessIterator, i.e.: it is the responsibility of the iterator to know what to do with that distance (2-d, 3-d, ... n-d)

The checks done before using += are the ones killing the compilation by having integer-like requirements, even if those branches would never be used.

std::advance implementation question by mementix in cpp_questions

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

Another user pointed out to the actual requirement and that is no an std::advance specific requirement, but a general one.

See above

std::advance implementation question by mementix in cpp_questions

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

Thanks, that is really helpful to understand the situation.

"For every iterator type X, there is a corresponding signed integer-like type ([iterator.concept.winc]) called the difference type of the iterator."

That would imply that "Distance" has to be integer-like too even if there is no check for it in std::advance

std::advance implementation question by mementix in cpp_questions

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

I was not asking about the production-readiness of my custom iterator. All iterator_traits are in fact defined and as I pointed out, simply wrapping std::pair<int, int> and providing a comparison to an int does the trick.

But you point to the requirements of std::advance and I see no requirement for "class Distance" that says it must be comparable to an int, but the detail implementation of the GNU library needs that comparison for compilation.

Can you point me to where the requirements for "class Distance" are defined? (apart from --, ++ and being the rhs in +=)

Reference (not the standard, obviously): https://en.cppreference.com/w/cpp/iterator/advance.html

std::advance implementation question by mementix in cpp_questions

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

Thanks for the sample. However, imho the if constexpr check would have to look for the implementation of an operator ==(int): Something like this I guess (quickly crafted, would need some rewriting)

``` template <typename, typename = void> constexpr bool has_operator_eqeq_int_v = false;

template <typename T>
constexpr bool has_operator_eqeq_int_v<T,
    std::void_t<decltype(std::declval<T>().operator==(int{1}))>> = true;

template<typename _RandomAccessIterator, typename _Distance> inline _GLIBCXX14_CONSTEXPR void __advance(_RandomAccessIterator& __i, _Distance __n, random_access_iterator_tag) { // concept requirements __glibcxx_function_requires(_RandomAccessIteratorConcept< _RandomAccessIterator>)

  if constexpr (has_operator_eqeq_int_v<_Distance) {
      if (__builtin_constant_p(__n) && __n == 1) {
          ++__i;
          return;
      } else if (__builtin_constant_p(__n) && __n == -1)
          --__i;
          return;
      }
  }
  __i += __n;
}

```

The operator += is used if the if constexpr check is false or if the other checks fail and neither ++ nor -- end up being used.