C2066 error in rnn.h

I tried to compile a basic program with libtorch, but a C2066 error occurred.
Program’s code is below

#include <torch/torch.h>

int main()
{
	auto a = torch::ones({ 2, 2 });
}

The error C2066 occurred in line 110 of rnn.h.

using RNNFunctionSignature = std::tuple<Tensor, Tensor>(
      /*input=*/const Tensor&,
      /*state=*/const Tensor&,
      /*params=*/TensorList,
      /*has_biases=*/bool,
      /*layers=*/int64_t,
      /*dropout=*/double,
      /*train=*/bool,
      /*bidirectional=*/bool,
      /*batch_first=*/bool);

My compile enviroment is as follows:
Windows 10
Visual Studio 2017 (v141) with/std:c++latest

Same here. I think VS2017 do not support the alias of the std::function by this way. So, you can just replace:

    using RNNFunctionSignature = std::tuple<Tensor, Tensor>(
        /*input=*/const Tensor&,
        /*state=*/const Tensor&,
        /*params=*/TensorList,
        /*has_biases=*/bool,
        /*layers=*/int64_t,
        /*dropout=*/double,
        /*train=*/bool,
        /*bidirectional=*/bool,
        /*batch_first=*/bool);

by

    typedef std::function<std::tuple<Tensor, Tensor>(
        /*input=*/const Tensor&,
        /*state=*/const Tensor&,
        /*params=*/TensorList,
        /*has_biases=*/bool,
        /*layers=*/int64_t,
        /*dropout=*/double,
        /*train=*/bool,
        /*bidirectional=*/bool,
        /*batch_first=*/bool)> RNNFunctionSignature;

or in a more modern way

    using RNNFunctionSignature = 
    std::function<std::tuple<Tensor, Tensor>(
        /*input=*/const Tensor&,
        /*state=*/const Tensor&,
        /*params=*/TensorList,
        /*has_biases=*/bool,
        /*layers=*/int64_t,
        /*dropout=*/double,
        /*train=*/bool,
        /*bidirectional=*/bool,
        /*batch_first=*/bool)>;

both works with vs2017 (using at least C++11 for the “using” way)

2 Likes

Oh, now it works! thanks :slight_smile: