Libtorch with c++20 on MSVC

I’m trying to integrate the libtorch C++ frontend into a project that relies on some C++20 (std:c++latest) features. Libtorch will not compile out of the box with MSVC. I get errors related to std::result_of and std::result_of_t being used (in C++17.h), which have been deprecated in favor of std::invoke_result and std::invoke_result_t in C++20.

So it looks like I have two options:

  1. Trying to dig into the libtorch source code and use std::invoke_result instead, without fully understanding the code (and then fix any subsequent errors I run into).
  2. Downgrade my project to use C++17, which requires replacing a lot of lines (mostly designated initializers) with more error-prone code.

Neither one sounds very fun. Will libtorch support C++20 any time soon?

4 Likes

I plan also to use LibTorch and C++ 20 (mainly focusing on concepts).
Is it sufficient just to fix result_of or it’s more complex task?
Were you able to do it or just gave up?

I don’t see any activity here so I assume nobody in torch team is interested in compiling it
with modern c++ :frowning:

I’m having the same issue. Need to downgrade project now to get things running using libtorch.

I have the same issue, I tried to compile app with Clang and GCC and everything works fine even with C++20, but with MSVC we need to downgrade standard

1 Like

Does anybody know any plans related to this issue?

Please, libtorch people, can you roll out a version for c++20. It’s 2022, and we are stuck with c++14!
Even if with c++17, I got error below:
libtorch/include/ATen/Functions.h:12966:3: error: reference to ‘optional’ is ambiguous
optional device_{};
^
libtorch/include/ATen/Operators.h:89:7: note: candidate found by name lookup is ‘c10::optional’
class optional;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/optional:585:7: note: candidate found by name lookup is ‘std::optional’
class optional

I have used pytorch with C++17 for one year and it works perfectly.

Did you use “using namespace std;”? Your problem should be gone after remove this line.

Libtorch 2.0 has been released now. I have test it with c++/latest and it works perfectly.