一般来说,我试图使用std :: variant来创建一个声明式的“联合枚举”类型,我需要在列表中描述一个位置(UITableView/UICollectionView et.al) 。swifty objective-C++ std :: variant
在斯威夫特这正是我需要做的:
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 *)
当我尝试包括#include (or #import) <variant>
我得到在XCode中出现variant file not found
的编译器错误。
任何方式来做到这一点?
'std :: variant'是一个C++ 17功能,可能不支持您正在使用的编译器。 –
如果您愿意,我会接受您的答案 –