【发布时间】:2023-03-19 21:56:02
【问题描述】:
一般来说,我正在尝试使用 std::variant 来创建我需要的声明性“联合枚举”类型来描述列表中的位置(UITableView/UICollectionView 等)。
在 Swift 中,这正是我需要做的:
enum Location {
case Header
case Footer
case Index(NSIndexPath)
}
我的 API 允许使用“标题”位置(部分和第 0 行的任意组合)、页脚(以及根据部分更改的部分和动态行号的组合)或特定索引路径进行调用。
在 c++ 中,我相信有一个 std::variant http://en.cppreference.com/w/cpp/utility/variant 允许这种行为:
我需要在 Objective-C++ 中执行此操作,但出现编译器错误
enum class Location {
Header,
Footer
};
std::variant<Location,Index> location ; (NSIndexPath *)
当我尝试在 XCode 中包含 #include (or #import) <variant> 时,我收到了 variant file not found 的编译器错误。
有什么办法吗?
【问题讨论】:
-
std::variant是您使用的编译器可能不支持的 C++17 功能。 -
如果你愿意,我会接受你的回答
标签: c++ ios enums std objective-c++