Dangit. Gonna have to upgrade to MSVC's latest...

I've been using MSVC 19 happily for a while now, with no particular rush to play with C++20 something...

Until today I tried to use a templated lambda with a parameter pack.

1
2
3
4
  auto arg_in = [&arg] <typename...Args> ( Args...args ) -> bool
  {
    return (... || (arg == args));
  };

MSVC 19 couldn't cut it.

Foo.

[edit] fixed a typo...
Last edited on
2019's 16.11.2 is the panacea you need for that.

There is even a flag/IDE setting to compile against C++20 instead of C++:latest.
I have 16.11.2 set to C++:latest, but this does not compile.

According to conformance table it's supported since 16.2:
https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance

VS 2022 can't compile as well.

Yeah, Clang++ 9.0 did it just fine with -std=c++2a.

All for a little readability later, I guess.
Didn't test it, but it looks like you wrote template where you should have written typename.
Argh. Alas, that was just a typo when posting here.
lol, I never saw this syntax anyway, but now it compiles fine..
As a compilable test program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>

int main()
{
	int arg {10};

	const auto arg_in {[&arg] <typename...Args> (Args...args) -> bool
	{
		return (... || (arg == args));
	}};

	std::cout << std::boolalpha << arg_in(1, 2, 3, 4, 10, 20, 30) << '\n';
	std::cout << std::boolalpha << arg_in(1, 2, 3, 4) << '\n';
}



true
false


Nice lambda!
Duthomhas wrote:
Yeah, Clang++ 9.0 did it just fine with -std=c++2a.

Can confirm, at least with Clang++ 10.0.0. I use -std=c++2a when using C++20 and it works fine.
That's something I never saw before. Looks awfully handy.

Welcome to MS22 :)
Topic archived. No new replies allowed.