用于可变参数模板向量的 mpl 样式 copy_if 元函数
我有一个元程序,可以与常规的 boost mpl 配合良好。它看起来更像下面这样。
template <class Vector, class ResultKind, class Custom>
struct FilterChildrenIfNotOk
{
typedef typename
copy_if<Vector,
or_<is_same<boost::mpl::placeholders::_1, ResultKind>,
IsOk<boost::mpl::placeholders::_1,
ResultKind,
Custom> > >::type type;
};
我正在尝试使用可变参数模板向量(mpl::vector)来编译它。为此,我使用此处找到的可变参数模板向量的实现: https://svn .boost.org/svn/boost/sandbox/variadic_templates
尽管有一些测试,但我在存储库中找不到 copy_if、remove_if 和 count_if 的可用实现。那些元程序在那里,但我找不到它们?或者,您能否帮助我实现其中之一,使其也支持 mpl 占位符。提前感谢您的帮助。
I've a meta-program that works fine with the regular boost mpl. It looks more like the following.
template <class Vector, class ResultKind, class Custom>
struct FilterChildrenIfNotOk
{
typedef typename
copy_if<Vector,
or_<is_same<boost::mpl::placeholders::_1, ResultKind>,
IsOk<boost::mpl::placeholders::_1,
ResultKind,
Custom> > >::type type;
};
I'm trying to compile it using variadic templates vector (mpl::vector). For that, I'm using the implementation of variadic templates vector found here: https://svn.boost.org/svn/boost/sandbox/variadic_templates
I could not find usable implementations of copy_if, remove_if, and count_if in the repo, although there are some tests. Are those meta-programs there and I'm just not able to find them? Alternately, can you please help me implement one of them such that it also supports mpl placeholders. Thanks for your help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们从一个提示开始:折叠比人们想象的更强大。例如,计算序列中元素的数量只需应用初始状态为 0 的
fold
以及采用状态(到目前为止的元素数量)和一个元素的函数,然后返回 <代码>the_state + 1。例如,现在您可以编写
count_if
吗? (显然使用fold
)如果你做不到,我会帮助你,直到你成功。
Let's start with an hint: fold is way more powerful than one would think. For example, counting the number of elements in a sequence just consists in applying
fold
with the initial state 0 and the function that takes a state (the number of elements so far) and an element, and returnthe_state + 1
.Now can you write
count_if
, for example? (usingfold
obviously)If you don't manage to I will help you out until you succeed.