[fusion][mpl] Get type from fusion sequence using mpl::at_c
Hi, I am trying to get the type of the first element in a fusion vector using mpl::at_c. This seems simple enough. // Here is the code #include <boost/fusion/sequence/container/vector.hpp> #include <boost/mpl/at.hpp> int main() { typedef boost::fusion::vector<int,int> VectorType; typedef boost::mpl::at_c<VectorType,0>::type value0; return 0; } This won't compile on vc-8.0, and I get the following error message: ...patience... ...found 467 targets... ...updating 2 targets... msvc.compile.c++ bin\msvc-8.0\debug\example2.obj example2.cpp using native typeof boost\boost/mpl/begin_end.hpp(35) : error C2903: 'apply' : symbol is neither a class template nor a function template boost\boost/mpl/aux_/at_impl.hpp(33) : see reference to class template instantiation 'boost::mpl::begin<Sequence>' being compiled with [ Sequence=VectorType ] boost\boost/mpl/at.hpp(45) : see reference to class template instantiation 'boost::mpl::at_impl<Tag>::apply<Sequence,N>' being compiled with [ Tag=boost::fusion::fusion_sequence_tag, Sequence=VectorType, N=boost::mpl::long_<0> ] examples\example2.cpp(11) : see reference to class template instantiation 'boost::mpl::at_c<Sequence,N>' being compiled with [ Sequence=VectorType, N=0 ] boost\boost/mpl/begin_end.hpp(35) : error C2027: use of undefined type 'boost::mpl::begin_impl<boost::fusion::fusion_sequence_tag>' boost\boost/mpl/begin_end.hpp(35) : error C2059: syntax error : '<' boost\boost/mpl/begin_end.hpp(35) : error C2039: 'type' : is not a member of '`global namespace'' boost\boost/mpl/begin_end.hpp(35) : error C2238: unexpected token(s) preceding ';' boost\boost/mpl/aux_/at_impl.hpp(33) : error C2039: 'type' : is not a member of 'boost::mpl::begin<Sequence>' with [ Sequence=VectorType ] boost\boost/mpl/aux_/at_impl.hpp(34) : error C2146: syntax error : missing ',' before identifier 'type' boost\boost/mpl/aux_/at_impl.hpp(34) : error C2065: 'type' : undeclared identifier boost\boost/mpl/aux_/at_impl.hpp(35) : error C2955: 'boost::mpl::advance' : use of class template requires template argument list boost\boost/mpl/advance.hpp(60) : see declaration of 'boost::mpl::advance' boost\boost/mpl/aux_/at_impl.hpp(35) : error C2039: 'type' : is not a member of 'boost::mpl::advance' boost\boost/mpl/advance.hpp(60) : see declaration of 'boost::mpl::advance' boost\boost/mpl/aux_/at_impl.hpp(35) : error C2146: syntax error : missing ';' before identifier 'iter_' boost\boost/mpl/aux_/at_impl.hpp(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int boost\boost/mpl/aux_/at_impl.hpp(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int boost\boost/mpl/aux_/at_impl.hpp(37) : error C2065: 'iter_' : undeclared identifier boost\boost/mpl/aux_/at_impl.hpp(37) : error C2955: 'boost::mpl::deref' : use of class template requires template argument list boost\boost/mpl/deref.hpp(35) : see declaration of 'boost::mpl::deref' boost\boost/mpl/aux_/at_impl.hpp(37) : error C2371: 'boost::mpl::at_impl<Tag>::apply<Sequence,N>::type' : redefinition; different basic types with [ Tag=boost::fusion::fusion_sequence_tag, Sequence=VectorType, N=boost::mpl::long_<0> ] boost\boost/mpl/aux_/at_impl.hpp(35) : see declaration of 'boost::mpl::at_impl<Tag>::apply<Sequence,N>::type' with [ Tag=boost::fusion::fusion_sequence_tag, Sequence=VectorType, N=boost::mpl::long_<0> ] call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 >nul cl /Zm800 -nologo -TP /Z7 /Od /Ob0 /W3 /GR /MDd /Zc:forScope /Zc:wchar_t /wd4675 /EHs @"bin\msvc-8.0\debug\example2.obj.rsp" -c -Fo"bin\msvc-8.0\debug\example2.obj" ...failed msvc.compile.c++ bin\msvc-8.0\debug\example2.obj... ...skipped <pbin\msvc-8.0\debug>example2.exe for lack of <pbin\msvc-8.0\debug>example2.obj... ...failed updating 1 target... ...skipped 1 target...
-----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Chris Weed Hi, I am trying to get the type of the first element in a fusion vector using mpl::at_c. This seems simple enough. ---- I'm a noob to fusion but do you want fusion::result_of::at_c instead?
I tried this, but it seems to be the result of the at_c function which is a reference. I would like to get the type of the element. I suppose I could use a meta-function to strip off the &, but it seems like the mpl version of at_c should do what I want. Chris On 1/18/07, Sohail Somani <s.somani@fincad.com> wrote:
-----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Chris Weed
Hi, I am trying to get the type of the first element in a fusion vector using mpl::at_c. This seems simple enough.
----
I'm a noob to fusion but do you want fusion::result_of::at_c instead? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
All the at functions would return you a reference, not a copy anyway. So they are doing the right thing. Stripping the reference is the right thing to do. -----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Chris Weed Sent: Sat 1/20/2007 9:31 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [fusion][mpl] Get type from fusion sequenceusingmpl::at_c I tried this, but it seems to be the result of the at_c function which is a reference. I would like to get the type of the element. I suppose I could use a meta-function to strip off the &, but it seems like the mpl version of at_c should do what I want. Chris On 1/18/07, Sohail Somani <s.somani@fincad.com> wrote:
-----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Chris Weed
Hi, I am trying to get the type of the first element in a fusion vector using mpl::at_c. This seems simple enough.
----
I'm a noob to fusion but do you want fusion::result_of::at_c instead? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
It appears another option is as follows: result_of::value_of<result_of::begin<VectorType>::type>::type or for an arbitrary index N enum { N=2 }; result_of::value_of<result_of::advance_c<result_of::begin<VectorType>::type,N>::type>::type Chris On 1/20/07, Sohail Somani <s.somani@fincad.com> wrote:
All the at functions would return you a reference, not a copy anyway. So they are doing the right thing. Stripping the reference is the right thing to do.
-----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Chris Weed Sent: Sat 1/20/2007 9:31 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [fusion][mpl] Get type from fusion sequenceusingmpl::at_c
I tried this, but it seems to be the result of the at_c function which is a reference. I would like to get the type of the element. I suppose I could use a meta-function to strip off the &, but it seems like the mpl version of at_c should do what I want. Chris
On 1/18/07, Sohail Somani <s.somani@fincad.com> wrote:
-----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Chris Weed
Hi, I am trying to get the type of the first element in a fusion vector using mpl::at_c. This seems simple enough.
----
I'm a noob to fusion but do you want fusion::result_of::at_c instead? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Chris Weed wrote:
I tried this, but it seems to be the result of the at_c function which is a reference. I would like to get the type of the element. I suppose I could use a meta-function to strip off the &, but it seems like the mpl version of at_c should do what I want.
value_at should be your friend. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Chris Weed wrote:
Hi, I am trying to get the type of the first element in a fusion vector using mpl::at_c. This seems simple enough.
// Here is the code #include <boost/fusion/sequence/container/vector.hpp> #include <boost/mpl/at.hpp>
int main() { typedef boost::fusion::vector<int,int> VectorType;
typedef boost::mpl::at_c<VectorType,0>::type value0; return 0; }
You'll need to include the at.hpp counterpart of fusion, or bring in the whole set of intrinsics: #include <boost/fusion/sequence/intrinsic.hpp> Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
participants (3)
-
Chris Weed
-
Joel de Guzman
-
Sohail Somani