C++ C++;函子初始化
在下面的代码示例中,我无法理解C++ C++;函子初始化,c++,C++,在下面的代码示例中,我无法理解{}的用途。为什么JU不做单元类型(…)而不是单元类型{}(…)?我只是在这里放了一个简化版本,希望能显示足够的上下文。原始代码以防您需要更多信息 #define DEFINE_QUANTIZED_RNN_CELL(..., cell_type, ... ) \ ... # what's the purpose of {} in the following line? \ return cell_type{}(
{}
的用途。为什么JU不做单元类型(…)
而不是单元类型{}(…)
?我只是在这里放了一个简化版本,希望能显示足够的上下文。原始代码以防您需要更多信息
#define DEFINE_QUANTIZED_RNN_CELL(..., cell_type, ... ) \
...
# what's the purpose of {} in the following line? \
return cell_type{}( \
...); \
}
using quantized_lstm_cell_type = LSTMCell<QuantizedCellParams>;
DEFINE_QUANTIZED_RNN_CELL(..., quantized_lstm_cell_type, ...);
template <typename cell_params>
struct LSTMCell {
using hidden_type = std::tuple<Tensor, Tensor>;
hidden_type operator()(...) const override {
...
}
};
#定义量化单元(…,单元类型,…)\
...
#下一行中{}的目的是什么\
返回单元格类型{}(\
...); \
}
使用量化的_lstm _cell _type=LSTMCell;
定义量化单元(…,量化单元类型,…);
模板
结构LSTMCell{
使用隐藏的类型=std::tuple;
隐藏类型运算符()(…)常量重写{
...
}
};
cell\u type{}
构造cell\u type
的临时实例。假设cell\u type
公开了一个操作符()
,您需要一个实例来调用它-因此您不能简单地说cell\u type()
。例如
struct cell_type { void operator()() { } };
cell_type{}(); // OK, creates temporary instance and invokes it
cell_type(); // Creates temporary instance, but doesn't invoke it
我猜
DEFINE\u QUANTIZED\u RNN\u CELL
需要类型而不是实例,这就是为什么它使用{}
CELL\u type{}
构造CELL\u type
的临时实例。假设cell\u type
公开了一个操作符()
,您需要一个实例来调用它-因此您不能简单地说cell\u type()
。例如
struct cell_type { void operator()() { } };
cell_type{}(); // OK, creates temporary instance and invokes it
cell_type(); // Creates temporary instance, but doesn't invoke it
我猜DEFINE\u QUANTIZED\u RNN\u CELL
需要一个类型而不是一个实例,这就是它使用{}
的原因