【发布时间】:2017-04-18 12:51:17
【问题描述】:
我有下一个代码:
template<class RandomIt>
static void SelectionSort(RandomIt first, RandomIt last) {
decltype(*first) res[length];
}
例如,我像下面这样调用这个函数:
int test[] = { 1, 2, 3, 4 };
SelectionSort(std::begin(test), std::end(test));
那么RandomIt 就是int*,不是吗?并且decltype(*first) 返回int& 而不是我需要的int。如何更改它以获取 int 类型?有可能吗?
【问题讨论】:
-
std::remove_reference_t<decltype(*first)> -
注意如果
length不是编译时常量,那么res[length]不是标准C++。 -
@aschepler,它是一个常数。