So I've always been a fan of C/C++. At my previous position I was almost strictly using C only for my part of the project (we also used quite a bit of Java). Towards the end I got really involved with Python (which I wish I was using more of now), but by current job is 99% C++.
One of the things I liked about Python was the ability to return more than 1 value/object from a function. And late last week I ran into a situation where that is exactly what I wanted in CPP. Boost tuple provided just that.
#include <boost/tuple/tuple.hpp>
using boost::make_tuple;
boost::tuples::tuple<float, float, int, float> getStuff()
{
return make_tuple<0.1,0.2,3,0.4>;
}
main()
{
boost::tuples::tuple<float, float, int, float> tup = getStuff();
if(tup<0>.get() == 0.1) /* cheer */ ;
if(tup<1>.get() == 0.2) /* cheer */ ;
if(tup<2>.get() == 3) /* cheer */ ;
if(tup<3>.get() == 0.4) /* cheer */ ;
}
While not as pretty as Python, but it works.
Nick
One of the things I liked about Python was the ability to return more than 1 value/object from a function. And late last week I ran into a situation where that is exactly what I wanted in CPP. Boost tuple provided just that.
#include <boost/tuple/tuple.hpp>
using boost::make_tuple;
boost::tuples::tuple<float, float, int, float> getStuff()
{
return make_tuple<0.1,0.2,3,0.4>;
}
main()
{
boost::tuples::tuple<float, float, int, float> tup = getStuff();
if(tup<0>.get() == 0.1) /* cheer */ ;
if(tup<1>.get() == 0.2) /* cheer */ ;
if(tup<2>.get() == 3) /* cheer */ ;
if(tup<3>.get() == 0.4) /* cheer */ ;
}
While not as pretty as Python, but it works.
Nick
No comments:
Post a Comment