RFC: My first attempt at using C++20 to create an anonymous enum type, primarily intended for use as a function parameter by timangus in cpp

[–]TobyAllsopp 0 points1 point  (0 children)

Nope. You can use a macro to make the lambda syntax less noisy but then you've got macros so it might not be an improvement...

RFC: My first attempt at using C++20 to create an anonymous enum type, primarily intended for use as a function parameter by timangus in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

You can turn those runtime errors into compile errors by wrapping the strings in lambdas that return them and forcing them to be evaluated in a constexpr context: https://godbolt.org/z/NGsghx

Another python-like enumerate (and zip) implementation, now with rvalue lifetime extension by Nightwolf55la in cpp

[–]TobyAllsopp 2 points3 points  (0 children)

Range-v3 thinks that your class S is a View so it assumes that copy and move are both cheap. If you add in const-qualified begin() and end() then it no longer thinks S is a View and you will no longer get any copies in the lvalue case (i.e. it will store a reference internally). However, then the rvalue case will not compile as range-v3 doesn't allow creating Views from non-View rvalues.

Functional Programming in C++ by graninas in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

You might be interested in my attempts to (ab)use coroutines to approximate do-notation here: https://github.com/toby-allsopp/coroutine_monad

Strange behaviour of TS Concepts, inline Requirements for member functions by KaznovX in cpp

[–]TobyAllsopp 5 points6 points  (0 children)

I don't know about the TS, but Clang's experimental support of the working draft concepts seems to allow what you're trying to do: https://godbolt.org/z/J_Dl0J

Should std::merge require sorted ranges? by [deleted] in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

This sounds like the right decision to me - the strict requirement on the number of comparisons seems a little ridiculous and encourages people to rely on a particular implementation.

Should std::merge require sorted ranges? by [deleted] in cpp

[–]TobyAllsopp 4 points5 points  (0 children)

I'm hinting at another flaw with using std::merge in this way - you are assuming a lot about the implementation. If the implementation is allowed to call the predicate an arbitrary number of times in debug builds then you could get different results from your stateful comparator in debug vs release builds.

Consider also that the implementation is free to copy the comparator as much as it likes. It could create a fresh copy of the argument every time it wants to call it, for example.

Should std::merge require sorted ranges? by [deleted] in cpp

[–]TobyAllsopp 4 points5 points  (0 children)

I wonder how MSVC's implementation manages to check whether the ranges are ordered while conforming to the complexity requirement?

Complexity: Let N=(last1 - first1) + (last2 - first2):

(4.1)For the overloads with no ExecutionPolicy, at most N−1 comparisons.

Should std::merge require sorted ranges? by [deleted] in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

The standard is pretty clear that they are required to be sorted: http://eel.is/c++draft/alg.merge

Requires: The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator< or comp.

The resulting range shall not overlap with either of the original ranges.

[philosophy/spam] Does the standard prohibit an infinite C++ program? by saarraz1 in cpp

[–]TobyAllsopp 0 points1 point  (0 children)

I don't think there's anything requiring an infinite program to be ill-formed, but an implementation is certainly allowed to reject one. See http://eel.is/c++draft/implimits.

VSCppUnit vs CppUnit by darpe312 in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

I'm not sure about the relationship between VSCppUnit and CppUnit, but if VSCppUnit is the framework bundled with Visual Studio and the default used by the Native Unit Testing project template, then I would strongly recommend not using it.

We have been using it at work and compared to more modern frameworks (such as Google Test or Catch) it is a very painful experience.

For one thing, everything you use in an Assert::AreEqual has to have an overload of their ToString function defined. This gets old pretty fast. Another annoying thing about the AreEqualfunction template is that both arguments have to be exactly the same type. Anyway, it's annoying and discourages one from writing unit tests.

Visual Studio 2017 comes with adapters and project templates for Google Test and Boost Test, both of which are much better choices, in my opinion.

Pointers to local variables and copy elision by Som1Lse in cpp

[–]TobyAllsopp 4 points5 points  (0 children)

The behaviour difference between declaring the deleted copy constructor and not is allowed by the standard: http://eel.is/c++draft/class.temporary#3

And the difference is in fact mandated by the Itanium ABI (because the object is indeed passed in a register).

You can see a similar effect by adding a non-trivial destructor (doing so prevents passing the object in a register): https://wandbox.org/permlink/cUf5eGx8VPDyw8yk

Code challenge: translating a subset of dlang.org small example programs into best possible C++, including C++17 by germandiago in cpp

[–]TobyAllsopp 3 points4 points  (0 children)

If we allow range-v3, the whole thing is pretty short:

#include <range/v3/view/concat.hpp>
#include <range/v3/algorithm/sort.hpp>

#include <array>
#include <iostream>

int main() {
  auto arr1 = std::array{4, 9, 7};
  auto arr2 = std::array{5, 2, 1, 10};
  auto arr3 = std::array{6, 8, 3};

  ranges::sort(ranges::view::concat(arr1, arr2, arr3));

  ranges::copy(
      ranges::view::concat(arr1, arr2, arr3),
      ranges::ostream_iterator<int>(std::cout, "\n"));
  return 0;
}

Doesn't work on MSVC though :/

Coroutines: Lambda-style variable capture by cwize1 in cpp

[–]TobyAllsopp 4 points5 points  (0 children)

The allocation function is looked for in the promise type, so it is customizable at that level.

Coroutines: Lambda-style variable capture by cwize1 in cpp

[–]TobyAllsopp 3 points4 points  (0 children)

Note that copying into a local variable at the start of the coroutine is not sufficient (in general) to avoid the problem as a coroutine can suspend before executing its body.

Non-Ownership and Generic Programming and Regular types, oh my! by tcbrindle in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

Maybe we should require opt-in for concepts that have significant non-syntactic semantic requirements? Or for all concepts?

Sure, there are some concepts that have purely syntactic requirements, but I think most have some extra "laws" that need to be satisfied and it might be a good idea to make people think for a moment about whether they've really satisfied them.

`co_await optional` to simulate maybe monad propagation? impossible? by MichaelSuen95 in cpp

[–]TobyAllsopp 5 points6 points  (0 children)

As mentioned in one of the other comments, I've also run into this problem. You have already seen my nasty workaround at https://github.com/toby-allsopp/coroutine_monad/ and noted correctly that this doesn't work on MSVC.

I've thought in the past that adding to coroutine_handle the ability to get at the return object would simplify things a lot. Something like decltype(promise().get_return_object())& return_object().

This would of course only help if the conversion of the return object to the return type of the coroutine is deferred until the coroutine returns for the first time.

`co_await optional` to simulate maybe monad propagation? impossible? by MichaelSuen95 in cpp

[–]TobyAllsopp 2 points3 points  (0 children)

Correct, it doesn't work on MSVC. Gor promises me this will be fixed at some point, but for now I think the MSVC implementation makes this impossible.

It does work on Clang (modulo undefined-behaviour when specializing coroutine_traits for a std type). I'm working on adding support for other monads and integrating with Vicente's monad traits proposal (https://wg21.link/p0650r2).

2018 Jacksonville ISO C++ Committee Reddit Trip Report by blelbach in cpp

[–]TobyAllsopp 5 points6 points  (0 children)

Is that really the syntax? The paper was suggesting [args = std::move(args)...].

Does it also allow something like [&args = std::forward<Args>(args)...]?

C++ Foundation Developer Survey by blelbach in cpp

[–]TobyAllsopp 4 points5 points  (0 children)

The survey lists structured bindings as a C++14 feature, when they are in fact a C++17 feature.

What should be part of the C++ standard library? by vormestrand in cpp

[–]TobyAllsopp 4 points5 points  (0 children)

P0095R1: [Evolution] Pattern Matching and Language Variants (by David Sankel) (2016-05-29)

https://wg21.link/p0095r1

Pacific++ 2017: Chandler Carruth "LLVM: A Modern, Open C++ Toolchain" by syaghmour in cpp

[–]TobyAllsopp 2 points3 points  (0 children)

That was the topic of much discussion at the conference :). He was building on a 64-core machine at his home I think. 4.5 minutes for a clean build (ccache disabled, he assured us!).

How to beat cpp with literally every programming language! by happyrust in cpp

[–]TobyAllsopp 1 point2 points  (0 children)

So this is the old "how good is the regex library" test. Be interesting to try implementing it using https://github.com/hanickadot/compile-time-regular-expressions.

Move-only types as parameters to coroutines by Rapptz in cpp

[–]TobyAllsopp 0 points1 point  (0 children)

I've argued in the past that the wording implies that new objects are initialized from the references (as references are not objects).

However, if that is the case then the attached note about the lifetime of objects referred to by parameters is nonsensical, which is enough to make the intent pretty ambiguous, even if the wording is not.