Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ BOOST_FOREACH在模板内不工作?_C++_Templates_Boost - Fatal编程技术网

C++ BOOST_FOREACH在模板内不工作?

C++ BOOST_FOREACH在模板内不工作?,c++,templates,boost,C++,Templates,Boost,我尝试在模板函数中使用BOOST_FOREACH,并使用自定义的、但与类型参数无关的迭代器。我得到4-5个错误,表明我的迭代器类没有很好地定义为迭代器 在没有BOOST_FOREACH的情况下重写循环,或者“取消模板化”函数,可以消除错误 这是已知的BOOST_FOREACH限制吗 编辑 对不起。一些代码: template <class T> T fun() { T result(0.0); BOOST_FOREACH(const math::IntegerVec

我尝试在模板函数中使用BOOST_FOREACH,并使用自定义的、但与类型参数无关的迭代器。我得到4-5个错误,表明我的迭代器类没有很好地定义为迭代器

在没有BOOST_FOREACH的情况下重写循环,或者“取消模板化”函数,可以消除错误

这是已知的BOOST_FOREACH限制吗

编辑 对不起。一些代码:

template <class T>
T fun()
{
    T result(0.0);

    BOOST_FOREACH(const math::IntegerVector &v, math::IntegerVectorRange(math::IntegerVector(2 , 2 ,2)))
    {
        // Do stuff.
    }

    return result;
}
模板
T fun()
{
T结果(0.0);
BOOST_FOREACH(const math::IntegerVector&v,math::IntegerVectorRange(math::IntegerVector(2,2,2)))
{
//做事。
}
返回结果;
}
IntegerVector*类型定义良好,在模板之外工作良好。它们也不依赖于T

完全错误是:

make[1]: Entering directory `/home/panayk/Workspace/petros-game'
Making all in src/c++
make[2]: Entering directory `/home/panayk/Workspace/petros-game/src/c++'
depbase=`echo fluid/Tracer.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
    /bin/bash ../../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../..   -I/usr/include/python2.7 -I/usr/include -O2 -I/usr/include/python2.7 -MT fluid/Tracer.lo -MD -MP -MF $depbase.Tpo -c -o fluid/Tracer.lo fluid/Tracer.cc &&\
    mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../.. -I/usr/include/python2.7 -I/usr/include -O2 -I/usr/include/python2.7 -MT fluid/Tracer.lo -MD -MP -MF fluid/.deps/Tracer.Tpo -c fluid/Tracer.cc  -fPIC -DPIC -o fluid/.libs/Tracer.o
In file included from /usr/include/boost/iterator/iterator_categories.hpp:15:0,
                 from /usr/include/boost/iterator/detail/facade_iterator_category.hpp:7,
                 from /usr/include/boost/iterator/iterator_facade.hpp:14,
                 from ./math/Vector.h:5,
                 from ./fluid/Tracer.h:4,
                 from fluid/Tracer.cc:1:
/usr/include/boost/mpl/eval_if.hpp: In instantiation of 'boost::mpl::eval_if<mpl_::bool_<false>, boost::range_const_iterator<math::IntegerVectorRange>, boost::range_mutable_iterator<math::IntegerVectorRange> >':
/usr/include/boost/foreach.hpp:364:13:   instantiated from 'boost::foreach_detail_::foreach_iterator<math::IntegerVectorRange, mpl_::bool_<false> >'
make[2]: Leaving directory `/home/panayk/Workspace/petros-game/src/c++'
./fluid/InterpolatorGrid.h:45:3:   instantiated from here
make[1]: Leaving directory `/home/panayk/Workspace/petros-game'
/usr/include/boost/mpl/eval_if.hpp:38:31: error: no type named 'type' in 'boost::mpl::eval_if<mpl_::bool_<false>, boost::range_const_iterator<math::IntegerVectorRange>, boost::range_mutable_iterator<math::IntegerVectorRange> >::f_ {aka struct boost::range_mutable_iterator<math::IntegerVectorRange>}'
In file included from fluid/Tracer.cc:3:0:
./fluid/InterpolatorGrid.h: In member function 'T fluid::InterpolatorGrid::interpolate(const std::vector<std::vector<std::vector<T> > >&, const RealVector&) const':
./fluid/InterpolatorGrid.h:45:3: error: no matching function for call to 'begin(const boost::foreach_detail_::auto_any_base&, boost::foreach_detail_::type2type<math::IntegerVectorRange, mpl_::bool_<false> >*, boost::enable_if_c<true, boost::mpl::and_<boost::mpl::not_<boost::foreach::is_noncopyable<math::IntegerVectorRange> >, boost::foreach::is_lightweight_proxy<math::IntegerVectorRange>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> > >::type*&)'
./fluid/InterpolatorGrid.h:45:3: note: candidates are:
/usr/include/boost/foreach.hpp:657:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::true_*)
/usr/include/boost/foreach.hpp:665:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::false_*)
/usr/include/boost/foreach.hpp:676:1: note: template<class T> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, mpl_::bool_<true> >::type> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, mpl_::bool_<true> >*, bool*)
/usr/include/boost/foreach.hpp:686:1: note: template<class T, class C> boost::foreach_detail_::auto_any<T*> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T*, C>*, mpl_::true_*)
./fluid/InterpolatorGrid.h:45:3: error: no matching function for call to 'end(const boost::foreach_detail_::auto_any_base&, boost::foreach_detail_::type2type<math::IntegerVectorRange, mpl_::bool_<false> >*, boost::enable_if_c<true, boost::mpl::and_<boost::mpl::not_<boost::foreach::is_noncopyable<math::IntegerVectorRange> >, boost::foreach::is_lightweight_proxy<math::IntegerVectorRange>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> > >::type*&)'
./fluid/InterpolatorGrid.h:45:3: note: candidates are:
/usr/include/boost/foreach.hpp:697:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::true_*)
/usr/include/boost/foreach.hpp:705:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::false_*)
/usr/include/boost/foreach.hpp:716:1: note: template<class T> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, mpl_::bool_<true> >::type> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, mpl_::bool_<true> >*, bool*)
/usr/include/boost/foreach.hpp:726:1: note: template<class T, class C> boost::foreach_detail_::auto_any<int> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T*, C>*, mpl_::true_*)
./fluid/InterpolatorGrid.h:45:3: error: no matching function for call to 'deref(const boost::foreach_detail_::auto_any_base&, boost::foreach_detail_::type2type<math::IntegerVectorRange, mpl_::bool_<false> >*)'
./fluid/InterpolatorGrid.h:45:3: note: candidate is:
/usr/include/boost/foreach.hpp:765:1: note: template<class T, class C> typename boost::foreach_detail_::foreach_reference::type boost::foreach_detail_::deref(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*)
make[2]: *** [fluid/Tracer.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
make[1]:进入目录“/home/panayk/Workspace/petros game”
在src/c中制作所有++
make[2]:进入目录“/home/panayk/Workspace/petros game/src/c++”
depbase=`echo fluid/Tracer.lo|sed's |[^/]*$|.deps/&;s| \.lo$||'`\
/bin/bash.././libtool--tag=CXX--mode=compileg++-DHAVE\u CONFIG\u H-I.-I../-I/usr/include/python2.7-I/usr/include-O2-I/usr/include/python2.7-MT流体/Tracer.lo-MD-MP-MF$depbase.Tpo-c-o流体/Tracer.lo流体/Tracer.cc&&\
mv-f$depbase.Tpo$depbase.Plo
libtool:compile:g++-DHAVE\u CONFIG\u H-I.-I../-I/usr/include/python2.7-I/usr/include-O2-I/usr/include/python2.7-MT流体/Tracer.lo-MD-MP-MF流体/.deps/Tracer.Tpo-c流体/Tracer.cc-fPIC-DPIC-o流体/.libs/Tracer.o
在/usr/include/boost/iterator/iterator_categories.hpp:15:0中包含的文件中,
来自/usr/include/boost/iterator/detail/facade\u iterator\u category.hpp:7,
来自/usr/include/boost/iterator/iterator_facade.hpp:14,
from./math/Vector.h:5,
来自/流体/示踪物。h:4,
来自流体/示踪物。cc:1:
/usr/include/boost/mpl/eval_if.hpp:“boost::mpl::eval_if”的实例化中:
/usr/include/boost/foreach.hpp:364:13:从“boost::foreach\u detail\u::foreach\u迭代器”实例化
make[2]:离开目录“/home/panayk/Workspace/petros game/src/c++”
./fluid/Interpologrid.h:45:3:从此处实例化
make[1]:离开目录“/home/panayk/Workspace/petros game”
/usr/include/boost/mpl/eval_if.hpp:38:31:错误:boost::mpl::eval_if::f_{aka struct boost::range_mutable_iterator}中没有名为“type”的类型
在流体/Tracer.cc中包含的文件中:3:0:
./fluid/interpologrid.h:在成员函数“T fluid::interpologrid::interpolate(const std::vector&,const RealVector&)const”中:
./fluid/interpologrid.h:45:3:错误:调用“begin(const boost::foreach\u detail\u::auto\u any\u base&,boost::foreach\u detail\u::type2type*,boost::enable\u if\u c::type*&)”时没有匹配函数
/fluid/Interpologrid.h:45:3:注:候选对象为:
/usr/include/boost/foreach.hpp:657:1:注意:模板boost::foreach_detail_uu::auto_uany boost::foreach_detail_u::begin
/usr/include/boost/foreach.hpp:665:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::begin
/usr/include/boost/foreach.hpp:676:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::begin(boost::foreach\u detail\uuu::auto\u any,boost::foreach\u detail\uu detail*)
/usr/include/boost/foreach.hpp:686:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::begin
./fluid/interpologrid.h:45:3:错误:调用“end(const boost::foreach_detail_uu::auto_any_base&,boost::foreach_detail_uuu::type2type*,boost::enable_if_c::type*&)”时没有匹配函数
/fluid/Interpologrid.h:45:3:注:候选对象为:
/usr/include/boost/foreach.hpp:697:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::end
/usr/include/boost/foreach.hpp:705:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::end
/usr/include/boost/foreach.hpp:716:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::end(boost::foreach\u detail\uuuu::auto\u any\u t,boost::foreach\u detail\uuu::type2type*,bool*)
/usr/include/boost/foreach.hpp:726:1:注意:模板boost::foreach\u detail\uuu::auto\u any boost::foreach\u detail\uu::end
./fluid/interpologrid.h:45:3:错误:调用“deref(const boost::foreach\u detail\u::auto\u any\u base&,boost::foreach\u detail\u::type2type*)时没有匹配函数
/流体/插值网格。h:45:3:注:候选人为:
/usr/include/boost/foreach.hpp:765:1:注意:模板类型名称boost::foreach\u detail\u::foreach\u参考::类型boost::foreach\u detail\u::deref(boost::foreach\u detail\u::auto\u any\t,boost::foreach\u detail\u::type2type*)
生成[2]:***[fluid/Tracer.lo]错误1
生成[1]:***[all recursive]错误1
make:**[全部]错误2
等等。这对我来说太难理解了,但是IntegerVectorRange::begin()在那里并返回一个常量迭代器。IntegerVectorRange::end()也是如此

编辑2(IntegerVectorRange)
类积分迭代器
:public boost::迭代器
<
积分迭代器,
常数积分,
boost::前向遍历标记
>
{
私人:
积分电流;
常数积分起点、极限;
无效增量();
布尔相等(常量整数迭代器和其他)常量;
常量IntegerVector&dereference()常量;
公众:
IntegerVector迭代器(const IntegerVector&start,
常数积分和极限);
IntegerVector迭代器(const IntegerVector¤t,
常数积分与星
class IntegerVectorIterator
: public boost::iterator_facade
<
    IntegerVectorIterator,
    const IntegerVector,
    boost::forward_traversal_tag
>
{
private:
    IntegerVector current;
    const IntegerVector start, limit;

    void increment();
    bool equal(const IntegerVectorIterator& other) const;
    const IntegerVector &dereference() const;

public:
    IntegerVectorIterator(const IntegerVector &start,
                          const IntegerVector &limit);
    IntegerVectorIterator(const IntegerVector &current,
                          const IntegerVector &start,
                          const IntegerVector &limit);

    friend class boost::iterator_core_access;
};

class IntegerVectorRange
{
private:
    const IntegerVector start, limit;
    const IntegerVectorIterator end_it;
public:
    IntegerVectorRange(IntegerVector limit);
    IntegerVectorRange(IntegerVector start, IntegerVector limit);

    typedef IntegerVectorIterator const_iterator;

    const_iterator begin() const;
    const const_iterator &end() const;
};
eval_if<bool_<false>, range_const_iterator<...>, range_mutable_iterator<...> >