我经常想得到一个类模板参数的decltype以便进一步使用它,比如在我已经剥离并简化以显示我的问题的循环中:
template <typename T>
class Foo {
public:
T type; //This is my hack to get decltype of T
};
template <typename T>
class Bar {
public:
};
int main() {
for(auto& foo : fs) {
//Is there some way to get the decltype of the template without having to refer to some arbitrary T member of Foo?
auto bar = someFunction<decltype(foo.type)>();
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法获得模板参数的decltype而不做这个hack?如果没有,获得这样一个值的decltype的最佳解决方法是什么?
我在模板化代码时遇到第二步或第二步的问题.为了便于阅读,我已经将代码剥离了它的基本要素.
我查看了很多模板问题,但我真的无法解决我的确切问题.
我目前有一个类RIVRecord,我模仿这样
template <class T>
class RIVRecord
{
private:
std::vector<T> values;
public:
std::string name;
RIVRecord(std::string _name, std::vector<T> _values) { name = _name; values = _values; };
~RIVRecord(void) { };
size_t size() {
return values.size();
}
T* Value(int index) {
return &values[index];
}
}
Run Code Online (Sandbox Code Playgroud)
很容易.T类型通常是原始类型,例如浮点数和整数.然后我想把这些RIVRecords放在DataSet类中.这是我遇到更多困难的地方.没有模仿它会是这样的:
class RIVDataSet
{
private :
//How to template this??
vector<RIVRecord<float>> float_records;
vector<RIVRecord<int>> int_records;
public:
RIVDataSet(void);
~RIVDataSet(void);
//And this
void AddRecord(RIVRecord<float> record) {
//How would this work?
}
//And this?
RIVRecord<float> GetFloatRecord();
};
Run Code Online (Sandbox Code Playgroud)
我来自Java背景,所以vector<?>每当我问RIVRecord时,我都可以使用和进行类型检查.但这在C++中似乎不可能.我尝试使用可变参数模板但不确定如何使用模板中的所有类型构造向量: …
我正在尝试在 Ubuntu 20.04 上运行作为 systemd 服务安装在 virtualenv 内部的 mlflow 跟踪服务器,但收到一条错误消息,表明它无法找到 Gunicorn。这是我的日记
nov 27 10:37:17 Atrium-Power mlflow[81375]: Traceback (most recent call last):
nov 27 10:37:17 Atrium-Power mlflow[81375]: File "/home/praxasense/.miniconda3/envs/mlflow-server/bin/mlflow", line 8, in <module>
nov 27 10:37:17 Atrium-Power mlflow[81375]: sys.exit(cli())
nov 27 10:37:17 Atrium-Power mlflow[81375]: File "/home/praxasense/.miniconda3/envs/mlflow-server/lib/python3.9/site-packages/click/core.py", line 829, in __call__
nov 27 10:37:17 Atrium-Power mlflow[81375]: return self.main(*args, **kwargs)
nov 27 10:37:17 Atrium-Power mlflow[81375]: File "/home/praxasense/.miniconda3/envs/mlflow-server/lib/python3.9/site-packages/click/core.py", line 782, in main
nov 27 10:37:17 Atrium-Power mlflow[81375]: rv = self.invoke(ctx)
nov 27 10:37:17 Atrium-Power …Run Code Online (Sandbox Code Playgroud)