- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
需要知道使用什么技术来声明 std::variant
type 包含包含在给定 std::tuple
中的所有类型及其子元组(如果元素也是元组)递归。
例如,
std::tuple<int, std::tuple<int, double, std::tuple<float, double, std::string>>>
std::variant<int, double, float, std::string>
std::variant
中。 .
最佳答案
与 Boost.Mp11 ,这还不算太糟。
第一步是递归地展平输入列表。我们有 mp_flatten
,但这只会进行一次扁平化 - 我们需要递归调用它。可能有更好的方法来做到这一点,但到目前为止我想出的最好方法是使用 mp_iterate
具有只有在执行某些操作时才会变平的函数:
// maybe_flatten succeeds only if it actually flattens
// (once we're flat, it's ill-formed, we use that a terminating condition for mp_iterate)
template <typename L,
typename U=mp_flatten<L>,
typename = std::enable_if_t<not mp_same<L, U>::value>>
using maybe_flatten = U;
template <typename L>
using recursive_flatten = mp_back<mp_iterate<L, mp_identity_t, maybe_flatten>>;
recursive_flatten
,那么我们需要做的就是确保类型是唯一的并将其重命名为变体:
template <typename L>
using to_variant = mp_rename<mp_unique<recursive_flatten<L>>, std::variant>;
->
),以便您可以编写按顺序调用的函数。我不确定它是否更好:
template <typename L>
using recursive_flatten2 = thread<
mp_iterate<L, mp_identity_t, maybe_flatten>,
mp_back>;
template <typename L>
using to_variant2 = thread_q<
L,
mp_quote<recursive_flatten2>,
mp_quote<mp_unique>,
mp_bind_q<mp_quote<mp_apply_q>, mp_quote<std::variant>, _1>
>;
关于c++ - 将 std::tuple 递归转换为 std::variant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61639962/
我创建了一个简单的 Variant 类来存储字符串、整数、 double 等。我正在尝试使用 std::map 类型的映射但我收到了这个奇怪的错误: In file included from /us
我有一个整数数组来检索 std::variant 中的内容。但是编译失败,报错No matching function to call 'get' .您能否解释原因,并提出实现相同目的的可行解决方案?
我的问题涉及 boost::variant 转换与 C++ 中的 std::vector 的混合。在我的项目中,我使用变体作为 SQL 的输出。我将始终只使用一种类型的变体。我想要做的是从变量、变量
(警告:虽然它乍一看可能是一个问题,但这是 而不是 一个初学者级别的问题。如果您熟悉“让强制”这个短语或者您曾经查看过 VBA 规范,请继续阅读。) 假设我有一个 Variant 类型的表达式,我想将
我正在使用一个相当笨拙的 c 接口(interface)来存储集合。 LowLevelStorer 类表示我为此接口(interface)编写的包装器。 Storer 类是一个高级类,它与Data 有
我试图将两个变体组合成一个变体只是为了便于阅读。这是代码: using VariantType_basic = std::variant; using VariantType_vector = std
给定一个类型为 std::variant 的变量,我检查过它不包含C .如何将其转换为 std::variant ? std::variant convert(std::variant value)
使用boost:variant: #include #include #include template boost::variant _tuple_index(size_t i, const
在 answer 中对于这个 SO 问题: What is the equivalent of boost::variant in the C++ standard library? 提到boost:
自从在 Android Gradle 插件 0.13.0 中升级到 gradle 2.1 后,这个问题就出现了,但我一直无法理解为什么有时会记录此警告。 考虑此 block 以根据变体类型重命名 AP
我想为变量实现一个模板方法。 但是根据输入是否为 int 变量(char、short、int),我想处理它与输入为 float 变量(float、double、long double)的情况有所不同。
boost::variant通过 boost::variant<>::types 公开其变体类型列表, 可以方便地与 boost::mpl::for_each 一起使用. std::variant缺少
歌词: 我尝试通过 MPI 实现任务池。所以我需要某种 RPC,但它可以在我的程序的不同部分之间工作,这意味着处理器 A 希望处理器 B 以参数 D 调用函数 C。我们不能像处理线程那样在进程之间传递
目前我的库使用 boost::optional 和 boost::variant。由于 C++17 已经发布,我想添加一个选项,它可以与 boost 和 std 一起使用。 所以我成功地测试了带有 b
假设我有: class TypeA { }; class TypeB { }; typedef boost::variant Type; 没关系: void foo(Type t) { }; int
假设我有一个嵌套的 boost::variant -类型TNested包含一些类型和一些其他 boost::variant类型(它本身不能再次包含 boost::variant types ,因此不会
使用带有 gradle 插件版本 3.3.0-alpha11 的 Android Studio 3.3 Canary 11。尝试同步 gradle 时会抛出以下错误 WARNING: API 'var
我看过这篇关于使用 std::variant 的文章.这是因为以下代码引发了代码分析警告: void CChristianLifeMinistryHtmlView::OnTimer(UINT_PTR
我有一个 Delphi 6 类对象,其中包含 30 个变体的数组,每个变体都通过不同的索引属性公开。例如: property responseCode: integer Index 7
...或在内部快速更改类型 std::variant在源代码中。 下面是列表本身及其容器元素的头文件中的代码。 // HVector.hh class HVector: public std::vec
我是一名优秀的程序员,十分优秀!