vector of the boost
I trying to use 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 ..
but I receive the error : error: conversion from 'std::vector' to non-scalar type 'std::vector >' requested
EDIT:
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;
and I define typedef in .h file
typedef boost::variant<mesh::Entity&, mesh::Vertex, mesh::Edge> zeroVariant;
typedef std::vector<zeroVariant> zeroVector;
and now i've got following errors:
/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/detail/reference_content.hpp: In member function '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: instantiated from '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: instantiated from '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: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl(int, int, Visitor&, VoidPtrCV, mpl_::false_, NoBackupFlag, Which*, step0*) [with Which = 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: instantiated from 'static typename Visitor::result_type boost::variant::internal_apply_visitor_impl(int, int, Visitor&, VoidPtrCV) [with 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: instantiated from 'typename Visitor::result_type boost::variant::internal_apply_visitor(Visitor&) [with Visitor = boost::detail::variant::assign_storage, 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:2085:13: instantiated from '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: instantiated from '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::variant]' /usr/include/c++/4.5/bits/vector.tcc:312:4: instantiated from '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: instantiated from '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: instantiated from here /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]' is private /softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:526:9: error: within this context
thanks in advance!!!!!
You'll need to change the type of 'zeros' - it cant convert from std::vector<mesh::Vertex>
to a vector of your variant type. Use some typedefs to make the code less verbose too:
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 ..
Also the line if (EntityS == "V")
is not correct and will probably fail. use strcmp or just compare the first char of the string.
上一篇: 在boost中实现的地图以及如何更改它
下一篇: 提升的向量