gpt4 book ai didi

c++ - 从 mpl 折叠表达式中检索迭代器位置

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:45 26 4
gpt4 key购买 nike

如何使用 boost::mpl 获取以下折叠类型的索引(这是某种 mpl::set 但不完全是)。 value iter::pos::value 不知何故未定义??

using unique_types =
typename mpl::fold<
mpl::vector<int,double,float,float,float>
, mpl::set0<>
, mpl::insert<mpl::placeholders::_1, mpl::placeholders::_2> /** _1 = State = set<...>, _2 element of NodeTypes*/
>::type;

using iter = typename boost::mpl::find< unique_types , int>::type;

std::cout << iter::pos::value << std::endl; // <<<< Not defined!

在线编译:Coliru

最佳答案

using types = mpl::vector<int, double, float, float, float>
using unique_types<types, mpl::set0<>, mpl::insert<_1, _2>>::type;
using iter = mpl::find<unique_edge_types, int>::type;
// std::cout << iter::pos::value << std::endl;
// error: 'boost::mpl::iter<boost::mpl::s_item<...a lot of text... > >::pos'
// has not been declared (mpl::s_item is a piece of mpl::set implementation)

虽然 edge_types 是一个 mpl::vector,但 unique_edge_types 是(取决于实现细节)一个 mpl::set,并且 mpl::find 不适用于 mpl::set。发生类似的错误

using unique_types = mpl::set<int, double, float>;
using iter = mpl::find<unique_types, int>::type;
// std::cout << iter::pos::value << std::endl;
// error: 'boost::mpl::iter<boost::mpl::set<...a lot of text... > >::pos'
// has not been declared

您可以使用返回 mpl::vector 的标准函数 mpl::unique:

#include <boost/mpl/unique.hpp>
#include <boost/type_traits/is_same.hpp>

using unique_types = mpl::unique<types, boost::is_same<_1,_2>>::type;

关于c++ - 从 mpl 折叠表达式中检索迭代器位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28588637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com