Open Neargye opened 4 years ago
When I had a working MSVC setup, I used to report the compiler bugs I found, but they were rarely fixed. Now I've just given up.
BTW, I'm likely to make a major update to this library after the NDC{TechTown} conference (later this week) where I'm presenting other techniques for achieving the same functionality. The code will be very much shorter after that.
Thanks for the answer.
I definitely want to try a new update, I really liked this dry-comparisons
for sweet syntax.
Of course, I would like to use it on Windows, unfortunately it is necessary to work (
Really stoked to try this out after seeing your TechTown talk, but unfortunately, MSVC spits out "error C1202: recursive type or function dependency context too complex".
Really hope you can get some version of this library MSVC-compatible!
Thank you. I've spent a lot of time the last few days, trying to simplify the code, but things are not going well (unless you count 3 filed compiler bug reports as "going well.") It's primarily the conditional noexcept
specifiers that trip the compilers, but also the return type deduction.
Here's compilation with MSVC. It took removing all conditional noexcept
specifiers, and rewriting a few of the -> decltype()
specifiers.
https://gcc.godbolt.org/z/96Zhvw
I'll see if it is possible to simplify the code by having conditional support for noexcept
(ugly macros, depending on compiler make and version.) The current implementation is more than a little bit messy.
Proof of concept implementation supporting latest clang, gcc and MSVC. Sacrifices are made regarding primarily noexcept
, but in some cases also SFINAE friendly return type deduction. This includes all the stuff I mentioned at NDC{TechTown}, plus an extra performance and safety thing I thought of on the way home, so it's in many cases better than what's on this git repo. It's missing the function call functionality, and needs a ton of tests. There's also a weird work around for a gcc bug I haven't been able to pinpoint yet (CTAD deduction guide fails)
Feel free to play with it.
The new version looks great.
On my test RETURN_FOLD(x) THRICE((x))
for msvc work ok.
A terrible thought, but what if we allow this syntax?
std::vector<int> s{1, 1, 1};
if (all_of(s) == 1) ...
Proof of concept implementation(only for all_of and ==) https://godbolt.org/z/N5JrhT
That's problematic, and there already is one:
#include <algorithm>
if (std::all_of(s.begin(), s.end(), [](auto x) { return x == 1; })
...
Or, if I get my higher order functions in place properly:
#include <algorithm>
if (std::all_of(s.begin(), s.end(), equal_to(1)))
...
I agree, just a funny idea that came at night.
But if (std::all_of(s.begin(), s.end(), [](auto x) { return x == 1; })
more code that if (all_of(s) == 1)
:D
Why all_of
is lambda?
template <typename ... Ts >
constexpr auto all_of(Ts&& ... vs) THRICE(op_t<decltype(and_exprs), decltype(vs)...>(and_exprs, FWD(vs)...))
``` seems ok.
Proof of concept implementation supporting latest clang, gcc and MSVC. Sacrifices are made regarding primarily
noexcept
, but in some cases also SFINAE friendly return type deduction. This includes all the stuff I mentioned at NDC{TechTown}, plus an extra performance and safety thing I thought of on the way home, so it's in many cases better than what's on this git repo. It's missing the function call functionality, and needs a ton of tests. There's also a weird work around for a gcc bug I haven't been able to pinpoint yet (CTAD deduction guide fails)Feel free to play with it.
Hmm, maybe I'm just being thick here, but I can't get the following example to work, which would be my primary use-case for this:
#include <iostream>
enum class E {A,B,C};
int main()
{
E e = E::A;
if (e == any_of(E::A, E::B, E::C)) { std::cout << "e is in any of E\n"; }
}
This is on VS 16.2.4, /std:C++latest. Error output is:
DryCompTest.cpp(148,11): error C2672: 'operator __surrogate_func': no matching overloaded function found
DryCompTest.cpp(148,5): error C2893: Failed to specialize function template 'unknown-type <lambda_12>::operator ()(_T1 &&...) noexcept(<expr>) const'
DryCompTest.cpp(148,5): message : With the following template arguments:
DryCompTest.cpp(148,5): message : '_T1={E, E, E}'
Have I fundamentally misunderstood the syntax?
Thank you @tagsemb . I'm not sure I understand that error, but I'm glad the latest version does work with your example code.
Why is all_of
a lambda, @Neargye? It's just one of many changes made while navigating the numerous compiler bugs. It probably won't be what I settle for, but if it will be, it'll be because it works around a compiler bug.
It does indeed, cheers!
For anyone who is still interested in using it with MSVC, I got it compiled and ran in Microsoft Visual Studio Community 2019 (Version 16.11.5) with a minor change in CMake
set(CMAKE_CXX_STANDARD 20)
This is excellent, @bxk-sonavex. Please submit a PR with an updated CMakeLists.txt (where this requirement is for MSVC only).
@rollbear Done.