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

UE4 Mac构建编译报错 no member named “disjunction” in namespace “std”

背景

我的工程在编译iOS时,遇到如下报错:

2025-09-05 11:43:51:940 : /Users/bkdevops/_ios1/EngineSource/Engine/Source/Runtime/Core/Public/Containers/Array.h:46:53: error: no member named 'disjunction' in namespace 'std'
 

分析

由于WINDOWS的构包没有这个报错,因此先观察其(disjunction)定义。WINDOWS下定义在 C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\include\xtr1common ,如代码1,Mac下的定义在  

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/disjunction.h ,如代码2。

//代码1:
_EXPORT_STD template <class... _Traits>
struct disjunction : false_type {}; // If _Traits is empty, false_typetemplate <class _First, class... _Rest>
struct disjunction<_First, _Rest...> : _Disjunction<_First::value, _First, _Rest...>::type {// the first true trait in _Traits, or the last trait if none are true
};
//代码2:
// _Or always performs lazy evaluation of its arguments.
//
// However, `_Or<_Pred...>` itself will evaluate its result immediately (without having to
// be instantiated) since it is an alias, unlike `disjunction<_Pred...>`, which is a struct.
// If you want to defer the evaluation of `_Or<_Pred...>` itself, use `_Lazy<_Or, _Pred...>`
// or `disjunction<_Pred...>` directly.
template <class... _Args>
using _Or _LIBCPP_NODEBUG = typename _OrImpl<sizeof...(_Args) != 0>::template _Result<false_type, _Args...>;#if _LIBCPP_STD_VER >= 17template <class... _Args>
struct disjunction : _Or<_Args...> {};template <class... _Args>
inline constexpr bool disjunction_v = _Or<_Args...>::value;#endif // _LIBCPP_STD_VER >= 17

由于我的Mac构建机没有配置为 _LIBCPP_STD_VER  17 ,具体原因见我的下一篇博文(UE4 Mac构建编译报错 no template named “is_void_v” in namespace “std”-CSDN博客)。因此 disjunction 未定义。

最终方案

在UE4的使用了disjunction 的地方,改为下面形式:

#if PLATFORM_IOS
constexpr bool TArrayElementsAreCompatible_V = std::_Or<std::is_same<DestType, std::decay_t<SourceType>>, std::is_constructible<DestType, SourceType>>::value;
#else
constexpr bool TArrayElementsAreCompatible_V = std::disjunction<std::is_same<DestType, std::decay_t<SourceType>>, std::is_constructible<DestType, SourceType>>::value;
#endif

disjunction的含义

针对代码2,下面这个表格汇总了代码中关键部分及其含义:

代码片段

含义

#if _LIBCPP_STD_VER >= 17

条件编译预处理指令​:检查 libc++ 的配置宏 _LIBCPP_STD_VER是否表示支持 C++17 或更高版本。

_LIBCPP_STD_VER

libc++ 内部宏​:其整数值代表 libc++ ​目标遵循的 C++ 标准版本,例如 17代表 C++17,20代表 C++20。

template <class... _Args> struct disjunction : _Or<_Args...> {};

std::disjunction的主模板定义​:它继承自一个内部实现 _Or

std::disjunction

C++17 标准引入的模板​:对多个类型特性 (type traits)​​ 进行逻辑或 (OR) 运算的元函数。

template <class... _Args> inline constexpr bool disjunction_v = _Or<_Args...>::value;

C++17 标准引入的变量模板​:是 disjunction<_Args...>::value的简写,方便使用。

#endif

结束条件编译块。

🔧 ​std::disjunction的功能与原理

std::disjunction是一个模板元函数,它接受任意数量(变长模板参数 class... _Args)的类型特性(例如 std::is_integral<T>, std::is_floating_point<T>等),并计算它们的逻辑或。

  • 运算规则​:相当于 T1::value || T2::value || ... || Tn::value,但是在编译期进行的。

  • 短路求值​:这是 disjunction一个非常重要的特性。如果在模板参数包 _Args...中,​某个类型特性 Bivalue静态成员为 true,那么 disjunctionvalue就是 true,并且编译器会停止实例化后续的类型特性​(即不会去计算 Bj::value,其中 j > i)。这在后续的类型实例化代价高昂或可能导致编译错误时特别有用。

  • 继承关系​:std::disjunction<B1, B2, ..., BN>会公开继承自第一个 valuetrueBi类型。如果所有 Bi::value都为 false,则继承自最后一个 BN。这意味着你不仅可以获取最终的 ::value,有时还可以获取到符合条件的那个特性类型本身的信息。

💡 ​简单示例

#include <type_traits>
#include <iostream>int main() {// 检查类型 T 是否是整型或浮点型之一using T = double;if (std::disjunction_v<std::is_integral<T>, std::is_floating_point<T>>) {std::cout << "T is either integral or floating point.\n";} else {std::cout << "T is neither integral nor floating point.\n";}return 0;
}

在这个例子中,std::disjunction_v<>会在编译期计算 std::is_integral<double>::value || std::is_floating_point<double>::value。由于 double是浮点类型,第二个特性的 valuetrue,因此整个 disjunction_v的结果为 true

http://www.xdnf.cn/news/1465579.html

相关文章:

  • 企业为何仍困在“数据孤岛”?——从iPaaS重构信息流的实践路径
  • 一个专为地图制图和数据可视化设计的在线配色网站,可以助你制作漂亮的地图!
  • Leetcode—2749. 得到整数零需要执行的最少操作数【中等】(__builtin_popcountl)
  • 嵌入式系统学习Day31(多路IO复用)
  • Android Studio新版本编译release版本apk实现
  • 在Ubuntu 20.04的服务器上查找的服务器的IP地址
  • 2025最全的软件测试面试八股文(含答案+文档)
  • 属性关键字
  • Kubernetes(k8s) po 配置持久化挂载(nfs)
  • Ansible 角色使用指南
  • js设计模式-状态模式
  • 腾讯最新开源HunyuanVideo-Foley本地部署教程:端到端TV2A框架,REPA策略+MMDiT架构,重新定义视频音效新SOTA!
  • 2025精选5款AI视频转文字工具,高效转录秒变文字!
  • MySQL集群——主从复制
  • MongoDB 源码编译与调试:深入理解存储引擎设计
  • solidity的高阶语法
  • 【Linux】网络安全管理:SELinux 和 防火墙联合使用 | Redhat
  • 红黑树 + 双链表最小调度器原型
  • 【JMeter】分布式集群压测
  • 解锁上下文的力量:大型语言模型中的上下文工程全解析
  • Java基础篇02:基本语法
  • CAD:修改
  • 23.【C++进阶】异常(try、catch、throw)
  • SQL表一共有几种写入方式
  • 零基础入门AI: YOLOv5 详解与项目实战
  • 数据库存储大量的json文件怎么样高效的读取和分页,利用文件缓存办法不占用内存
  • 数据结构:排序
  • 【Day21】146.LRU缓存 (Least Recently Used)
  • 详细解读Docker
  • STC携手VEX发起全球首个碳资产RWA生态,泰国峰会即将引爆绿色金融