Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-07-07 04:02:35


"Andy Little" <andy_at_[hidden]> wrote
 David Abrahams wrote
> > Arkadiy's typeof from the Boost Files area at yahoogroups:
> > http://tinyurl.com/32mlf

(BTW tinyurl died when I tried it direct... look for typeof.zip on boost
yahoo files)

> >
> > No docs, lots of examples.

It has some docs , which are entirely adequate to get you going IMO.

>
> Thanks... I'll take a look.

Well . I've tested it and am pleased to report that it works well .. test
code at the end.

In relation to my physical_quantities library when you want a temporary, by
the time you've registered it
it may simpler to use the result_of approach, where there is no requirement
to register. But that is a problem particular to my library where new types
of unknown origin are being computed all the time in a calculation. IOW you
need result_of to compute typeof as in code below.

Whatever... it does the job well. .. worth a look.

regards
Andy Little

------------------------------------
#include <boost/typeof/typeof.hpp>
#include "pqs/pqs.hpp"

//Note: not available in pqs-1-01-04
#include "pqs/operators/binary_operator_functors.hpp"

#define BOOST_TYPEOF_REGISTRATION_GROUP \
 BOOST_TYPEOF_USER_GROUP +1

BOOST_TYPEOF_REGISTER_TYPE(pqs::q_length::m);
BOOST_TYPEOF_REGISTER_TYPE(pqs::q_time::s);

// required because a temporary result of calc
// is not same signature as q_velocity::m_div_s in pqs-2-00-01
typedef boost::result_of<
    pqs::operator_divides(pqs::q_length::m, pqs::q_time::s)
>::type anonymous_velocity;
BOOST_TYPEOF_REGISTER_TYPE(anonymous_velocity);

#undef BOOST_TYPEOF_REGISTRATION_GROUP

using namespace pqs;

// dummy function return test
BOOST_TYPEOF(q_length::m()/q_time::s()) my_func1()
{
     return q_length::m(1) / q_time::s(1);
}

int main()
{
    q_length::m m(1);
    q_time::s t(1);
    BOOST_AUTO(v, m/t);
    std::cout << v <<'\n';

    BOOST_TYPEOF(m/t) f1;
    std::cout << f1 <<'\n';

    q_velocity::m_div_s v1 = my_func1();
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk