[Proto] Building a mpl::vector from an expression

Hi, I am trying to build a mpl::vector from an expression like (string(),ClassA(),ClassB()) To get a mpl::vector<string,ClassA,ClassB> With string, ClassA and ClassB being not enough under control to protoify them with a proto::extends. I naively tried the following grammar struct BuildFlags : proto::or_< proto::when < proto::terminal<proto::_>, boost::mpl::vector<proto::_child>()
,
proto::when < proto::comma<BuildFlags,BuildFlags >, boost::mpl::push_back< BuildFlags(proto::_left),proto::_right>()
{}; Or some typeof variants of it, with no more success and I start wondering if I got on a rocky way leading me to unavoidable doom. Is there a way to do this or I should give up the idea? Thanks, Christophe _________________________________________________________________ Share your memories online with anyone you want. http://www.microsoft.com/middleeast/windows/windowslive/products/photos-shar...

AMDG christophe henry wrote:
I am trying to build a mpl::vector from an expression like
(string(),ClassA(),ClassB())
To get a mpl::vector<string,ClassA,ClassB>
<snip>
Is there a way to do this or I should give up the idea?
Does fold_tree help? In Christ, Steven Watanabe

Steven Watanabe wrote:
christophe henry wrote:
I am trying to build a mpl::vector from an expression like
(string(),ClassA(),ClassB())
To get a mpl::vector<string,ClassA,ClassB> <snip>
Is there a way to do this or I should give up the idea?
Does fold_tree help?
It does. #include <string> #include <boost/mpl/vector.hpp> #include <boost/mpl/push_back.hpp> #include <boost/proto/core.hpp> #include <boost/proto/transform.hpp> namespace proto = boost::proto; namespace mpl = boost::mpl; using proto::_; namespace My { struct ClassA {}; struct ClassB {}; template<class T> struct is_my : mpl::false_ {}; template<> struct is_my<std::string> : mpl::true_ {}; template<> struct is_my<ClassA> : mpl::true_ {}; template<> struct is_my<ClassB> : mpl::true_ {}; BOOST_PROTO_DEFINE_OPERATORS(is_my, proto::default_domain) struct FoldTreeToVector : proto::fold_tree< _ , mpl::vector0<>() , mpl::push_back<proto::_state, proto::_value>() > {}; } int main() { mpl::vector3<std::string, My::ClassA, My::ClassB> x = My::FoldTreeToVector()((std::string(), My::ClassA(), My::ClassB())); } -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (3)
-
christophe henry
-
Eric Niebler
-
Steven Watanabe