提升的向量

我试图使用boost :: variant

std::vector<boost::variant<mesh::Entity&, mesh::Vertex, mesh::Edge> > 
    xField::getZeros(const mesh::Region& s, char *EntityS) const
{
//Vertex  
  if( EntityS == "V" )
  {
    std::vector<mesh::Vertex> zeros;
    for(Region::vertexIterator itv = s.beginVertex(); 
        itv != s.endVertex(); ++itv )
    {
      if( abs(getVal(*itv)) < 1.e-12 )      
      zeros.push_back(*itv);
    }
      return zeros;    
  }
 else if ..

但我收到错误:错误:从'std :: vector'转换为非标量类型'std :: vector>'请求

编辑:

zeroVector xField::getZeros(const mesh::Region& s, char *EntityS) const
{
//Vertex  
  if( EntityS == "V" )
  {
    zeroVector zeros;
    for(Region::vertexIterator itv = s.beginVertex(); itv != s.endVertex(); ++itv )
    {
      if( abs(getVal(*itv)) < 1.e-12 )      
      zeros.push_back( zeroVariant(*itv) );
    }
      return zeros;

我在.h文件中定义了typedef

typedef boost::variant<mesh::Entity&, mesh::Vertex, mesh::Edge> zeroVariant;
typedef std::vector<zeroVariant> zeroVector;

现在我有以下错误:

/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/detail/reference_content.hpp:在成员函数'void boost :: detail :: variant :: assign_storage :: internal_visit(T&,int) const [with T = boost :: detail :: reference_content]':/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/detail/visitation_impl.hpp:130:9:实例化自'typename Visitor :: result_type boost :: detail :: variant :: visitation_impl_invoke_impl(int,Visitor&,VoidPtrCV,T *,mpl _ :: true_)[with Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void * ,T = boost :: detail :: reference_content,typename Visitor :: result_type = void,mpl _ :: true_ = mpl _ :: bool_]'/softs/boost/1.53.0/64/gcc/4.5.1/include/boost /variant/detail/visitation_impl.hpp:173:9:从'typename Visitor :: result_type boost :: detail :: variant :: visitation_impl_invoke(int,Visitor&,VoidPtrCV,T *,NoBackupFlag,int)实例化[with Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void *,T = boost :: detail :: reference_content,NoBackupFlag = boost :: v ariant :: has_fallback_type_,typename Visitor :: result_type = void]'/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/detail/visitation_impl.hpp:260:1:从' typename Visitor :: result_type boost :: detail :: variant :: visitation_impl(int,int,Visitor&,VoidPtrCV,mpl _ :: false_,NoBackupFlag,其中*,step0 *)[其中= mpl _ :: int_ <0>,step0 = boost :: detail :: variant :: visitation_impl_step,boost :: detail :: reference_content,boost :: mpl :: l_item,mesh :: Vertex,boost :: mpl :: l_item,mesh :: Edge,boost :: mpl :: l_end>>>>,boost :: mpl :: l_iter>,Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void *,NoBackupFlag = boost :: variant :: has_fallback_type_,typename Visitor :: result_type = void,mpl _ :: false_ = mpl _ :: bool_]'/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:2326:13:从静态类型名实例化Visitor :: result_type boost :: variant :: internal_apply_visitor_impl(int,int,Visitor&,VoidPtrCV)[Visitor = boost :: detail :: variant :: assign_storage, VoidPtrCV = void *,T0_ = mesh :: Entity&,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail :: variant :: void_,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant :: void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail: :variant :: void_,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,typename Visitor: :result_type = void]'/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:2337:13:从'typename Visitor :: result_type boost :: variant: :internal_apply_visitor(Visitor&)[带访问者= boost :: detail :: variant :: assign_storage,T0_ = mesh :: Entity&,T1 = mesh :: 顶点,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail :: variant :: void_,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant :: void_, T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,typename Visitor :: result_type = void]'/softs/boost/1.53.0/64/ gcc / 4.5.1 / include / boost / variant / variant.hpp:2085:13:从'void boost :: variant :: variant_assign(const boost :: variant&)'实例化[with T0_ = mesh :: Entity&,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail :: varia nt :: void_,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant :: void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_,T13 = boost: :detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,boost :: variant = boost :: variant]'/ softs /boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:2175:9:从'boost :: variant&boost :: variant :: operator =(const boost :: variant& )[with T0_ = mesh :: Entity&,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_, T5 = boost :: detail :: variant :: void_,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant :: void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_ ,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant: :void_,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,boost :: variant = boost ::变体]'/usr/include/c++/4.5/bits/vector.tcc:312:4:从'void std :: vector <_Tp,_Alloc> :: _ M_insert_aux(std :: vector <_Tp,_Alloc> :: iterator,const _Tp&)[with _Tp = boost :: variant,_Alloc = std :: allocator>,std :: vector <_Tp,_Alloc> :: iterator = __gnu_cxx :: __ normal_iterator *,std :: vector >>>,typename std :: _ Vector_base <_Tp,_Alloc> :: _ Tp_alloc_type :: pointer = boost :: variant *]'/usr/include/c++/4.5/bits/stl_vector.h:749:4:从'void std :: vector < _Tp,_Alloc> :: push_back(const value_type&)[with _Tp = boost :: variant,_Alloc = std :: allocator>,va lue_type = boost :: variant]'/home/mycode.cc:128:42:从这里实例化/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/detail/reference_content.hpp:62 :24:error:'boost :: detail :: reference_content&boost :: detail :: reference_content :: operator =(const boost :: detail :: reference_content&)[with RefT = mesh :: Entity&,boost :: detail :: reference_content = boost :: detail :: reference_content]'是private /softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:526:9:error:within this context

提前致谢!!!!!


你需要改变'零'的类型 - 它不能从std::vector<mesh::Vertex>转换为你的变体类型的向量。 使用一些typedefs来减少代码冗长:

typedef boost::variant<mesh::Entity&, mesh::Vertex, mesh::Edge> EvVariant;
typedef std::vector<EvVariant> EvVariantVector;

EvVariantVector xField::getZeros(const mesh::Region& s, char *EntityS) const
{
//Vertex  
  if( EntityS == "V" ) // This line is probably a bug!
  {
    EvVariantVector zeros; // Use the return type here!
    for(Region::vertexIterator itv = s.beginVertex(); itv != s.endVertex(); ++itv )
    {
      if( abs(getVal(*itv)) < 1.e-12 )      
      zeros.push_back(EvVariant(*itv));
    }
      return zeros;    
  }
 else if ..

另外,行if (EntityS == "V")不正确,可能会失败。 使用strcmp或只比较字符串的第一个字符。

链接地址: http://www.djcxy.com/p/51055.html

上一篇: vector of the boost

下一篇: How to Install boost on Ubuntu?