[variant][mpl] silly mistake in make_variant_over usage?

The following program fails to compile (148 lines of errors, will paste on request) with g++ (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2 in -std=c++11 mode. This is using Boost 1.59.0. Command line: g++ -std=c++11 -I ~/boost_1_59_0 -o make_variant make_variant.cpp I assume I'm making a simple error. I would appreciate your pointing it out. Thank you! (Is there a simpler way to obtain a variant of the result types of passed functions? I was hoping I could just write: boost::variant< std::result_of<Fns>::type... >.) #include <boost/variant/variant.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/transform.hpp> #include <type_traits> // std::result_of template < typename... Fns > typename boost::make_variant_over< boost::mpl::transform< boost::mpl::vector<Fns...>, std::result_of<boost::mpl::_1> > >::type multiplex(Fns && ... functions) { typedef typename boost::make_variant_over< boost::mpl::transform< boost::mpl::vector<Fns...>, std::result_of<boost::mpl::_1> > >::type return_t; // dummy for now return return_t(); } int main(int argc, char *argv[]) { boost::variant<int, char*> var = multiplex([argc](){ return argc; }, [argv](){ return argv[0]; }); return 0; }

On 8/28/2015 10:35 PM, Nat Goodspeed wrote:
The following program fails to compile (148 lines of errors, will paste on request) with g++ (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2 in -std=c++11 mode.
This is using Boost 1.59.0. Command line:
g++ -std=c++11 -I ~/boost_1_59_0 -o make_variant make_variant.cpp
I assume I'm making a simple error. I would appreciate your pointing it out. Thank you!
(Is there a simpler way to obtain a variant of the result types of passed functions? I was hoping I could just write: boost::variant< std::result_of<Fns>::type... >.)
This seems to work: typedef typename boost::make_variant_over< boost::mpl::vector< typename std::result_of<Fns()>::type...> >::type return_t; So probably this would to: typedef boost::variant< typename std::result_of<Fns()>::type...> >::type return_t; Except that the last one might be problematic with repeated return types. The documentation would know for sure. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com

On Fri, Aug 28, 2015 at 9:47 PM, Agustín K-ballo Bergé <kaballo86@hotmail.com> wrote:
On 8/28/2015 10:35 PM, Nat Goodspeed wrote:
(Is there a simpler way to obtain a variant of the result types of passed functions? I was hoping I could just write: boost::variant< std::result_of<Fns>::type... >.)
So probably this would to:
typedef boost::variant< typename std::result_of<Fns()>::type...> >::type return_t;
Thank you very much! Indeed, this works: typedef boost::variant< typename std::result_of<Fns()>::type... > return_t; So my silly mistake was omitting the parentheses. :-)
participants (2)
-
Agustín K-ballo Bergé
-
Nat Goodspeed