[gsoc] improving any and variant

A few little ideas that could eventually be joined to be a single GSoC project: - Allow visitation for Any. This can actually be generalized to any object that exposes a type_info, such as polymorphic objects. Techniques, including non-portable ones based on name mangling, could be experimented to get more efficient dispatch. - Add SBO to any. - Improve variant so that the functor doesn't require to expose a result_type. The result_type can be automatically deduced by "joining" all the possible return types obtained by boost::result_of. - Allow the easy construction of a visitor from lambda expressions, with a syntax like variant<int, std::string> a = "foo"; int b = match(a).with( args<int>(_1), args<std::string>(size(_1)) ); instead of the potentially more verbose struct my_visitor : static_visitor<int> { int operator()(int a) { return a; } int operator()(const std::string& b) { return b.size(); } }; variant<int, std::string> a = "foo";; int b = apply_visitor(my_visitor(), a);

A few little ideas that could eventually be joined to be a single GSoC project:
- Allow visitation for Any. This can actually be generalized to any object that exposes a type_info, such as polymorphic objects.
Techniques, including non-portable ones based on name mangling, could be experimented to get more efficient dispatch.
- Add SBO to any.
- Improve variant so that the functor doesn't require to expose a result_type. The result_type can be automatically deduced by "joining" all the possible return types obtained by boost::result_of.
- Allow the easy construction of a visitor from lambda expressions, with a syntax like
variant<int, std::string> a = "foo";
int b = match(a).with( args<int>(_1), args<std::string>(size(_1)) );
instead of the potentially more verbose
struct my_visitor : static_visitor<int> { int operator()(int a) { return a; } int operator()(const std::string& b) { return b.size(); } };
variant<int, std::string> a = "foo";;
int b = apply_visitor(my_visitor(), a);
Please add your ideas to the wiki. That's the place where students will look first. Regards Hartmut

What happened to dynamic_any btw? http://www.ddj.com/cpp/184403961 Mathias Gaunard schrieb:
A few little ideas that could eventually be joined to be a single GSoC project:
- Allow visitation for Any. This can actually be generalized to any object that exposes a type_info, such as polymorphic objects.
Techniques, including non-portable ones based on name mangling, could be experimented to get more efficient dispatch.
- Add SBO to any.
- Improve variant so that the functor doesn't require to expose a result_type. The result_type can be automatically deduced by "joining" all the possible return types obtained by boost::result_of.
- Allow the easy construction of a visitor from lambda expressions, with a syntax like
variant<int, std::string> a = "foo";
int b = match(a).with( args<int>(_1), args<std::string>(size(_1)) );
instead of the potentially more verbose
struct my_visitor : static_visitor<int> { int operator()(int a) { return a; } int operator()(const std::string& b) { return b.size(); } };
variant<int, std::string> a = "foo";;
int b = apply_visitor(my_visitor(), a);
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Mathias, On Sun, Mar 29, 2009 at 7:01 PM, Mathias Gaunard < mathias.gaunard@ens-lyon.org> wrote:
- Allow the easy construction of a visitor from lambda expressions, with a syntax like
variant<int, std::string> a = "foo";
int b = match(a).with( args<int>(_1), args<std::string>(size(_1)) );
instead of the potentially more verbose
struct my_visitor : static_visitor<int> { int operator()(int a) { return a; } int operator()(const std::string& b) { return b.size(); } };
variant<int, std::string> a = "foo";;
int b = apply_visitor(my_visitor(), a);
You may find this useful: https://svn.boost.org/svn/boost/sandbox/boost/type_switch.hpp http://lists.boost.org/Archives/boost/2003/10/54774.php I had started on it some years ago, but never followed through. It has some cool features, though, like pattern matching: using namespace boost::type_switch; variant< int , pair<int,double> , pair<int,int> , pair<double,int> > var; switch_(var) |= case_< pair<_1,_1> >(...) // matches pair<int,int> |= case_< pair<int,_> >(...) // matches pair<int,*> |= case_< pair<_,_> >(...) // matches pair<*,*> |= case_< int >(...) ; Eric

you might want to take a look at adobe::any_regular_t, and maybe pull in a few ideas from there. see http://stlab.adobe.com/group__asl__tutorials__value__t.html. Tony On Sun, Mar 29, 2009 at 10:01 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
A few little ideas [about boost::any...]
participants (5)
-
Eric Friedman
-
Franz Fehringer
-
Gottlob Frege
-
Hartmut Kaiser
-
Mathias Gaunard