Visual Studio CMake无法找到模板功能的专业化对象?

时间:2020-04-27 20:03:45

标签: c++ visual-studio templates cmake

因此,我已经有了递归模板类的这一部分。我已经在正常的Visual Studio项目中对其进行了测试,它的工作原理完全符合预期。

// emplace_back using a single argument to copy-construct the object.
template <typename FirstType, typename... RestTypes>
typename std::enable_if<std::is_copy_constructible<FirstType>::value, void>::type inline emplace_back(const FirstType& first, RestTypes&& ... rest) {
    new (&mydata[this->mysize]) FT(first);
    _structofarrays_base<RTs...>& base = *this;
    base.emplace_back(rest...);
}

// emplace_back using a single argument to move-construct the object.
template <typename FirstType, typename... RestTypes>
typename std::enable_if<std::is_move_constructible<FirstType>::value, void>::type inline emplace_back(FirstType&& first, RestTypes&&... rest) {
    new (&mydata[this->mysize]) FT(std::move(first));
    _structofarrays_base<RTs...>& base = *this;
    base.emplace_back(rest...);
}

// emplace_back using no arguments to construct the object.
template <typename... RestTypes>
inline void emplace_back(decltype(std::ignore), const RestTypes& ... rest) {
    new (&mydata[this->mysize]) FT();
    _structofarrays_base<RTs...>& base = *this;
    base.emplace_back(rest...);
}

// emplace_back using multiple arguments to construct the object.
template <typename... FirstTypes, typename... RestTypes>
inline void emplace_back(const std::tuple<FirstTypes...>& first, const RestTypes& ... rest) {
    std::apply([=](const FirstTypes& ... args) {new (&mydata[this->mysize]) FT(args...); }, first);
    _structofarrays_base<RTs...>& base = *this;
    base.emplace_back(rest...);
}

但是,当我将代码移到Visual Studio CMake项目时,突然出现以下错误: ...\structofarrays.hpp(345): error C2440: 'initializing': cannot convert from 'const FirstType' to 'FT' with [ FirstType=std::_Ignore ] and [ FT=short ]

本质上,我试图使用std::ignore作为参数,这应该导致它使用函数的第三版(默认构造函数),但是它试图使用第一版(复制构造函数) ),显然它不能将std::ignore转换为short。当我尝试使用std::tuple参数时,也会发生同样的事情;而不是使用适当的第四个函数,而是使用第二个(移动构造函数)。

让我感到困惑的部分是,它完全按照常规Visual Studio项目中的预期工作,并且当我切换到CMake项目时停止工作。这是怎么回事?

我正在使用Visual Studio 2019和C ++ 17。

编辑:将生成器从“忍者”更改为“ Visual Studio 16 2019”不能解决该问题。

0 个答案:

没有答案