转换元组类型

发布于 2025-01-01 13:50:38 字数 812 浏览 1 评论 0原文

所以我是提升 MPL 的新手,我不知道如何将它与标准类型一起使用。

我想要一个隐藏这种类型的元函数:

std::tuple<T0, T1, ..., TN>

变成这样:

std::tuple<
  std::function<T0(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
  std::function<T1(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
  ...,
  std::function<TN(...)>
>

这似乎可以用 transform,但我想要一个元组类型,而不是类型向量。 (它实际上不必使用 MPL,但我想它会更短?)

背景:目前我使用完全泛型类型,并且如果使用错误,就会依赖所有的地狱,但我想计算 TupleOfFunctions< /code> 以获得正确的错误。

template<class TupleOfValues, class TupleOfFunctions>
void f(TupleOfValues v, TupleOfFunctions fun)

So I'm new to boost MPL, and I don't know how to use it with standard types.

I want a metafunction that coverts this type:

std::tuple<T0, T1, ..., TN>

Into this:

std::tuple<
  std::function<T0(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
  std::function<T1(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
  ...,
  std::function<TN(...)>
>

and it seems like this could be done with transform, but I want to have a tuple-type, not a vector of types. (It doesn't have to use MPL actually, but I guess it would be shorter?)

Background: currently I use totally generic types and rely on all hell breaking loose if used wrong, but I want to calculate the TupleOfFunctions to get a proper error.

template<class TupleOfValues, class TupleOfFunctions>
void f(TupleOfValues v, TupleOfFunctions fun)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荆棘i 2025-01-08 13:50:38

下面的怎么样?

template<typename T> struct transform;
template<typename ...T>
struct transform<std::tuple<T...>> {
  typedef std::tuple<std::function<T(std::tuple<T...>, std::tuple<T...>)>...> type;
};

How about the following?

template<typename T> struct transform;
template<typename ...T>
struct transform<std::tuple<T...>> {
  typedef std::tuple<std::function<T(std::tuple<T...>, std::tuple<T...>)>...> type;
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文