- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个类似于 boost::mpl::find_if 的元函数,但不同之处在于它将从末尾开始遍历序列。我收到编译错误,我猜这些错误来自作为元函数参数传递的 mpl::lambda 的计算。对于我做错了什么的任何指示,我将不胜感激。
现在我正在尝试一个懒惰的解决方案(装饰原来的 find_if):
#include <boost/mpl/reverse.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/distance.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/advance.hpp>
#include <boost/mpl/next_prior.hpp>
#include <boost/mpl/lambda.hpp>
using boost::mpl::reverse;
using boost::mpl::find_if;
using boost::mpl::distance;
using boost::mpl::end;
using boost::mpl::advance;
using boost::mpl::prior;
using boost::mpl::lambda;
template<typename SEQ, typename pred>
struct rfind_if {
private:
// find the element in the reversed container
typedef typename reverse<SEQ>::type rev_SEQ;
typedef typename lambda<pred>::type expanded_pred;
typedef typename find_if<rev_SEQ, expanded_pred>::type rev_iter;
// compute the distance of the iterator
typedef typename distance<rev_iter, typename end<rev_SEQ>::type >::type dist;
public:
//compute the iterator
typedef typename advance<typename begin<SEQ>::type, typename prior<dist>::type>::type type;
};
问题是当尝试使用这个函数时:
typedef vector_c<int, 1, 2, 3, 6, 5, 4>::type test_vect;
typedef find<test_vect, int_<6>::type>::type it_cur;
typedef rfind_if<test_vect, lambda<less<deref<it_cur>::type, _1> >::type >::type it_swap;
std::cout << "it_swap=" << deref<it_swap>::type::value << "\n\n";
我收到神秘错误,我猜这些错误来自 lambda 计算:
/usr/include/boost/mpl/aux_/preprocessed/gcc/less.hpp:60: error: no type named ‘tag’ in ‘struct mpl_::void_’ (some more template noise)
/usr/include/boost/mpl/not.hpp:43: error: ‘value’ is not a member of ‘boost::mpl::aux::nested_type_wknd<boost::mpl::aux::iter_apply1 (some more template noise)
/usr/include/boost/mpl/aux_/preprocessed/gcc/iter_fold_if_impl.hpp:62: error: no type named ‘type’ in ‘struct boost::mpl::apply2<boost::mpl::protect<boost::mpl::aux::iter_fold_if_pred (some more template noise)
...and much more...
我已经测试了 rfind_if 的内部结构(没有将 lambda 作为模板参数传递)并且它有效,命名:
typedef vector_c<int, 1, 2, 3, 6, 5, 4>::type test_vect;
typedef boost::mpl::reverse<test_vect>::type rev_SEQ;
typedef find_if<rev_SEQ, less<int_<5>, _1> >::type rev_iter;
typedef distance<rev_iter, end<rev_SEQ>::type >::type dist;
typedef advance<begin<test_vect>::type, prior<dist>::type>::type it_begin;
boost::mpl::for_each< rev_SEQ >( value_printer() );
产生了正确的结果
我知道我的功能效率很低,但现在我想了解问题所在。之后我会写一个合适的实现。
最好的问候
最佳答案
据我所知,rfind_if
不是错误的原因,而是代码中的这个问题似乎取消了对 end
的引用的 test_vect
.
1)vector_c<int>
中元素的类型似乎integral_c<int>
, 不是 int_
.所以find<test_vect, int_<6>::type>::type
是end
的 test_vect
.因此取消引用 it_cur
在 deref<it_cur>::type
无效。
2)如果你的意思是 less<int_<6>, _1>
通过 less<deref<it_cur>::type, _1>
,自 test_vect
没有这样的元素,rfind_if<...>::type
是再次 end
的 test_vect
.所以在 deref<it_swap>::type::value
中取消引用它无效。
解决以上问题后,代码可以在 ideone 上编译.
关于c++ - 将 mpl lambda 表达式作为模板参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7947661/
下面的代码再现了一个我真的不理解 boost MPL 库的行为: #include #include #include using namespace boost; int main() {
我正在尝试使用 boost.mpl 编写一个小型元程序,该程序使用两个 channel 映射将“命名 channel ”与音频格式相匹配。 名称也是一个整数(枚举)。我试图在运行时实现的一个简单示例可
我正在尝试在 for_each 中使用 mpl_list #include #include #include #include #include #include #include #
我正在尝试对 mpl::string 应用转换,但无法对其进行编译。我正在使用 MS VC++2010 和 Boost 1.43.0。代码: #include #include #include
我正在尝试运行几年前编写的代码,该代码使用 matplotlib 中的 mpl。以前运行得很好,但现在突然抛出错误: from matplotlib import mpl ImportError: c
Boost MPL 文档指出 boost::map::equal "如果两个序列 Seq1 和 Seq2比较 _element_ _element_ 时是相同的。 但似乎没有检查关联序列映射是否相等元
假设我有一个 boost::mpl::vector “myvec”,例如这样定义: using myvec = boost::mpl::vector; 现在我想定义另一种类型 myvecex,它将每个
下面的代码尝试测试 boost::mpl::or_ 和 boost::mpl::and_ 的短路行为: #include #include #include #include #include
假设我有这些类型: template class Storage > struct AbstractFactoryUnit { virtual ~AbstractFactoryUnit()
我有一个类型列表定义为: typedef boost::mpl::list OriginalList; 我想创建不包含任何水果的第二个列表,即从第一个列表形成的结果列表将包含单一类型的 Brick。
我有以下内容: class Message { public: bool process() { return doProcess(); } protected
我试图在编译时使用 boost-mpl 连接字符串,但从 gcc 中收到错误。这是示例 - using namespace boost; using namespace std; template s
天哪,在使用 mpl 库时,弄清楚语法是一个碰运气的经历 (previous question)。比较两个 mpl 迭代器的正确语法是什么 - 即 it != v.end() 测试? template
我目前正致力于在我的应用程序中实现“捐赠”选项,并决定使用 PayPal(请参阅:Donate via in-app billing) 阅读文档等后,决定使用 PayPal 移动支付库 (MPL)。一
我想使用编译时 (MPL) for_each 检查给定的输入变量是否在 MPL 数组中,并再次从 MPL 数组中获取和获取输出变量。我正在尝试使用具有 2 个参数的函数对象,即 MPL 类型和输入。
我知道以下代码不起作用,因为 i 是运行时参数而不是编译时参数。但我想知道,是否有办法实现同样的目标。我有一个类列表,我需要调用其中每个类的模板函数。 void GucTable::refreshSe
我正在浏览 tutorial关于生成式编程,我偶然发现了MPL-value idiom: template class A { A(); public: static const A
我有元函数 FibIter。它计算与斐波那契数列中的数字(参数 Iter)对应的斐波那契数。然后我使用 mpl::transform 创建具有从 0 到 N 的斐波那契数列的 mpl::vector。
我试图用一些容器将每个元素包装在 mpl::set 中,例如 std::vector,尽管实际类型并不重要.我该怎么做?基本上我想从这里开始 using mySet = mpl::set; 对此 us
我有一个像这样的 boost::mpl 序列: typedef boost::mpl::vector TTypes; 我有一个特定用途的容器类,我想从我的 dll 中导出它: template cla
我是一名优秀的程序员,十分优秀!