我需要一个类型特征来检查参数包中的所有类型是否都是可复制构造的.这就是我到目前为止所做的.main函数包含一些测试用例,用于检查功能.
#include <type_traits>
#include <string>
#include <memory> 
template <class... Args0toN>
struct areCopyConstructible;
template<>
struct areCopyConstructible<> : std::true_type {};
template <class Arg0, class... Args1toN, class std::enable_if< !std::is_copy_constructible<Arg0>::value>::type* = nullptr >
struct areCopyConstructible : std::false_type {};
template <class Arg0, class... Args1toN, class std::enable_if< std::is_copy_constructible<Arg0>::value>::type* = nullptr >
struct areCopyConstructible : areCopyConstructible<Args1toN...> {};
int main()
{
  static_assert(areCopyConstructible<>::value, "failed");
  static_assert(areCopyConstructible<int>::value, "failed");
  static_assert(areCopyConstructible<int, std::string>::value, "failed");
  static_assert(!areCopyConstructible<std::unique_ptr<int> >::value, "failed");
  static_assert(!areCopyConstructible<int, std::unique_ptr<int> >::value, "failed");
  static_assert(!areCopyConstructible<std::unique_ptr<int>, int >::value, "failed");
}
我的想法是递归检查,包的头部元素是否是可复制构造的,并继续进行尾部.不幸的是,我没有这个想法来编译.我对可变参数模板的了解不是很先进.我想,启用 - 如果在模板列表中的参数包之后不起作用.我不知道.有没有人有好的建议,如何解决问题?