Skip to content

Instantly share code, notes, and snippets.

@Mizux
Created October 25, 2024 13:47
Show Gist options
  • Save Mizux/acf4e6e3e7e990e359ad133f2eb05cb0 to your computer and use it in GitHub Desktop.
Save Mizux/acf4e6e3e7e990e359ad133f2eb05cb0 to your computer and use it in GitHub Desktop.
Compile issue on x64 msvc 17 VS 2022 (19.41)
#include <iostream>
#include <cstdint>
#include <functional>
#include <string>
#include <optional>
//using F = std::function<int(int,int)>;
template <typename RType, typename DummyType = int64_t,
typename PType = int32_t,
typename FFunction = std::function<RType(PType, PType)>>
class Foo {
public:
Foo(PType p, FFunction f): p_(p), f_(std::move(f)) {}
RType func() const {
return f_(p_, p_);
}
PType p_;
const FFunction f_;
};
template<bool x> void bar() {
int c = 12;
auto lambda = [&c](int a, int b) -> int { return a*b+c;};
using L = decltype(lambda);
//using L = std:function<int(int,int)>;
std::cout << "blabla\n";
for(auto it: {1,2,3}) {
Foo<int, int, int, L> foo(42, lambda);
const auto a = foo.func();
std::cout << std::to_string(a) << '\n';
}
}
struct B { int x = -1; };
struct A {
std::optional<B> b;
};
int main() {
bar<true>();
A a = {
.b = B{.x = 3}
};
}
@Mizux
Copy link
Author

Mizux commented Oct 25, 2024

Run on godbolt.org using /std:c++20 /O2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment