我有使用例程這樣的一個複雜的代碼:參數包必須在這方面擴大
#include <memory>
#include <iostream>
#include <vector>
template <typename T> class C {
public:
typedef T Type;
};
class ParamInfo {
public:
bool value;
};
template <typename T>
void testR(
std::shared_ptr<typename std::enable_if<
std::is_same<int, T>::value || std::is_same<double, T>::value, T>::type>
¶m,
T value) {
param.reset(new T(value));
}
template <typename jsParamType, size_t paramIndex, typename... jsParamTypes>
bool testV(std::shared_ptr<typename jsParamType::Type> ¶m,
ParamInfo ¶mInfo) {
std::cout << param << "\n";
(*param)++;
testR<typename jsParamType::Type>(param, 10);
std::cout << typeid(param).name() << " ++ --> " << *param << std::endl;
paramInfo.value = true;
return true;
}
template <typename... jsParamType, size_t... paramIndex>
bool testU(std::tuple<std::shared_ptr<typename jsParamType::Type>...> ¶ms,
std::vector<ParamInfo> ¶msInfos,
std::index_sequence<paramIndex...>) {
bool r[] = {true,
testV<jsParamType, paramIndex, jsParamType...>(
std::get<paramIndex>(params), paramsInfos[paramIndex])...};
bool res = true;
for (size_t i = 0; i < sizeof...(jsParamType) + 1 && res == true; i++)
res &= r[i];
return res;
}
template <typename... jsParamType>
bool testU(std::tuple<std::shared_ptr<typename jsParamType::Type>...> ¶ms,
std::vector<ParamInfo> ¶msInfos) {
return testU<jsParamType...>(
params, paramsInfos, std::make_index_sequence<sizeof...(jsParamType)>{});
}
template <typename... jsParamType> void test() {
std::tuple<std::shared_ptr<typename jsParamType::Type>...> params =
std::make_tuple(std::shared_ptr<typename jsParamType::Type>(
new typename jsParamType::Type())...);
std::vector<ParamInfo> paramsInfos(sizeof...(jsParamType));
bool ret = testU<jsParamType...>(params, paramsInfos);
std::cout << ret << "\n";
}
int main() {
// your code goes here
test<C<int>, C<double>>();
test<>();
return 0;
}
雖然這個代碼編譯和下MSVC/GNUC++的作品,我得到「jsParamType:參數包必須在擴大本文中,」我真正的代碼在函數頭
template<typename jsParamType, size_t paramIndex, typename... jsParamTypes> bool testV(std::shared_ptr<typename jsParamType::Type>& param, ParamInfo& paramInfo)
此參數std::shared_ptr<typename jsParamType::Type>& param
我試圖知道是什麼原因。 在某些情況下是否需要std::forward
?
我知道它並不多,但真正的代碼是很複雜的發佈。
在我的測試中,在真實代碼中,沒有std::shared_ptr
我沒有得到錯誤,所以它必須與某些模板評估或參數推導相關。
我沒有得到任何與http://cpp.sh/8bkyb或http://rextester.com/HRK7676警告,我不編譯與Visual Studio 2015更新3 – Stargateur
「我有一個問題有些代碼我沒有展示給你,下面是一些可行的代碼,這有什麼問題?「我們不是心理學家。 –
沒錯,但真正的代碼是Adobe APIs,數百個文件等的混合體。 – mike