当前位置: 首页 > wzjs >正文

上海网站开发公司哪家好网站建设自学网

上海网站开发公司哪家好,网站建设自学网,个人用服务器,丰和园林建设集团网站## 问题描述 两个结构几乎相同的模板实现&#xff0c;一个能正常工作&#xff0c;另一个在 VS2019 和 GCC 中都会报错。 ## 最小化测试代码 // bug_report.cpp #include <type_traits> #include <string>template<typename T> struct Type2Type { using t…

## 问题描述

两个结构几乎相同的模板实现,一个能正常工作,另一个在 VS2019 和 GCC 中都会报错。

## 最小化测试代码

// bug_report.cpp
#include <type_traits>
#include <string>template<typename T> struct Type2Type { using type = T; };
template<typename T1, typename T2> struct IsSameType : std::false_type {};
template<typename T> struct IsSameType<T, T> : std::true_type {};// 工作正常的版本
template<size_t idx, typename TList> struct FindNthTypeInTypeList;
template<typename T, template <typename ...> class TList, typename ... Types>
struct FindNthTypeInTypeList<0,TList<T, Types...>> : public Type2Type<T> {};
template<size_t idx, template <typename ...> class TList, typename T, typename ... Types>
struct FindNthTypeInTypeList<idx, TList<T, Types ...>> : public FindNthTypeInTypeList<idx-1, TList<Types ...>> {};
template<size_t idx, typename TList> using FindNthTypeInTypeList_t = typename FindNthTypeInTypeList<idx, TList>::type;// 不能工作的版本
template<size_t idx, typename TList> struct GetAllTypesFromIdx;
template<template <typename ...> class TList, typename ... Types>
struct GetAllTypesFromIdx<0, TList<Types...>> : public Type2Type<TList<Types...>> {};
template<size_t idx, typename T, template <typename ...> class TList, typename ... Types>
struct GetAllTypesFromIdx<idx, TList<T, Types...>> : public GetAllTypesFromIdx<idx-1, TList<Types...>> {};
template<size_t idx, typename TList> using GetAllTypesFromIdx_t = typename GetAllTypesFromIdx<idx, TList>::type;// 测试类型列表
template<typename...> struct TypeList {};
using tc_typeList = TypeList<int, char, std::string, char*>;int main()
{// FindNthTypeInTypeList 测试 - 这些都能工作static_assert(IsSameType<FindNthTypeInTypeList_t<0, tc_typeList>, int>::value);static_assert(IsSameType<FindNthTypeInTypeList_t<1, tc_typeList>, char>::value);static_assert(IsSameType<FindNthTypeInTypeList_t<2, tc_typeList>, std::string>::value);static_assert(IsSameType<FindNthTypeInTypeList_t<3, tc_typeList>, char*>::value);static_assert(!IsSameType<FindNthTypeInTypeList_t<0, tc_typeList>, char>::value);// GetAllTypesFromIdx 测试 - 这些会报错static_assert(IsSameType<GetAllTypesFromIdx_t<0, tc_typeList>, TypeList<int, char, std::string, char*>>::value);// static_assert(IsSameType<GetAllTypesFromIdx_t<1, tc_typeList>, TypeList<char, std::string, char*>>::value);// static_assert(IsSameType<GetAllTypesFromIdx_t<2, tc_typeList>, TypeList<std::string, char*>>::value);// static_assert(IsSameType<GetAllTypesFromIdx_t<3, tc_typeList>, TypeList<char*>>::value);
}

## 错误信息

在 VS2019 和 GCC 中都会报错:
 

1>C:\...\MiniMPL\sources\UnitTest\UT_MiniMPL\src\tc_typeList_cpp11.cpp(135,9): error C2752: 'MiniMPL::GetAllTypesFromIdx<0,UnitTest::tc_typeList>': more than one partial specialization matches the template argument list
1>C:\...\MiniMPL\sources\MiniMPL\include\MiniMPL\typeList_cpp11.hpp(56,105): message : could be 'MiniMPL::GetAllTypesFromIdx<0,TList<Types...>>'
1>C:\...\MiniMPL\sources\MiniMPL\include\MiniMPL\typeList_cpp11.hpp(58,105): message : or       'MiniMPL::GetAllTypesFromIdx<idx,TList<T,Types...>>'
1>C:\...\MiniMPL\sources\UnitTest\UT_MiniMPL\src\tc_typeList_cpp11.cpp(135): message : see reference to alias template instantiation 'MiniMPL::GetAllTypesFromIdx_t<0,UnitTest::tc_typeList>' being compiled
1>C:\...\MiniMPL\sources\MiniMPL\include\MiniMPL\typeList_cpp11.hpp(59,176): error C2794: 'type': is not a member of any direct or indirect base class of 'MiniMPL::GetAllTypesFromIdx<0,UnitTest::tc_typeList>'
1>C:\...\MiniMPL\sources\UnitTest\UT_MiniMPL\src\tc_typeList_cpp11.cpp(135,9): error C2938: 'MiniMPL::GetAllTypesFromIdx_t' : Failed to specialize alias template

## 问题分析

1. 两个模板实现 `FindNthTypeInTypeList` 和 `GetAllTypesFromIdx` 的结构几乎完全相同

2. 它们都有:

   - 一个 `idx=0` 的特化

   - 一个通用的递归特化

   - 相同的类型列表处理方式

3. `FindNthTypeInTypeList` 能正常工作,所有测试都通过

4. `GetAllTypesFromIdx` 在 VS2019 和 GCC 中都会报错

## 预期行为

- 两个模板都应该能正常工作

- `FindNthTypeInTypeList` 应该返回指定索引的类型

- `GetAllTypesFromIdx` 应该返回从指定索引开始的所有类型

## 实际行为

- `FindNthTypeInTypeList` 按预期工作

- `GetAllTypesFromIdx` 报错,认为两个特化是同等特化的

## 环境信息

- 编译器:VS2019 和 GCC

- 标准:C++11 或更高

- 操作系统:Windows/Linux

## 可能的解决方案

1. 使用 SFINAE 来限制第二个特化只在 `idx>0` 时匹配

2. 重新设计模板特化,使其特化规则更明确

3. 等待编译器更新修复这个 bug

http://www.dtcms.com/wzjs/795848.html

相关文章:

  • 制作企业网站怎么报价北京vi设计哪家公司好
  • 湖北seo网站多少钱药监局网站建设方案
  • 淘宝联盟网站备案全球电子元器件采购平台
  • 网站前端语言帮忙做网站
  • 手机网站免费建设平台合肥seo网络优化公司
  • 网站建设需要注意的问题中亿丰建设集团股份有限公司官方网站
  • 设计网站建设价格WordPress登录界面个性化
  • 重庆网站设计软件网络营销具有哪些优势和吸引力
  • 重庆网站设计生产厂家wordpress 地址跳转
  • 十堰网站优化价格网页设计怎么写
  • 网站关键词优化怎么做的商城开发建设
  • 压缩图片在线网站免费wordpress函数the_posts
  • 有声小说网站开发群晖套件做网站
  • 桃城网站建设公司重庆本地网站有哪些
  • 网站导航菜单代码内容电商网站有哪些
  • 烟台微网站建设免费logo设计在线生成器官网
  • 查公司的国家网站有哪些哈尔滨网站制作哪家好薇
  • 绿色家园网站怎么做做网站开发的需求文档
  • 仓山福州网站建设品牌营销咨询机构
  • 优秀的手机网站案例分析wordpress plugins php speedy
  • 网站seo优化排名西宁网站建设公司排行
  • 网站怎么做下拉刷新可以免费进入的网站正能量域名
  • 北京公司网站建设价格wordpress dux推送代码
  • 免费做片头的网站网站外链建设与文章发布规范
  • 外贸公司域名哪个网站申请比较好网站建设企业开发
  • 广东广东深圳网站建设建设网站的费用属于
  • 天推广人的网站app网站与普通网站的区别
  • 新乡平原新区建设局网站ppt模板简洁大方
  • 分销网站怎么做金华手机建站模板
  • 广州网站搭建费用郑州网站建设贴吧