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?


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