|
Boost : |
From: Andy Little (andy_at_[hidden])
Date: 2006-09-05 00:27:50
Hi Boosters,
Is it possible to use fusion to do a compile time matrix?
The code below uses boost::tuple, but presumably fusion could do this stuff
better?
Things that might be useful include get column N, get cofactor<R,C> etc, etc.
Might be an interesting example for fusion, but I don't know ...
Its kind of fun anyway.
regards
Andy Little
---------------------
#include <quan/out/time.hpp>
#include <quan/out/reciprocal_time.hpp>
#include <boost/tuple/tuple.hpp>
template <int Rows, int Columns,typename TupleSequence>
struct rc_matrix{
TupleSequence seq;
// 0 based
template <int Row, int Column>
typename boost::tuples::element<
Columns * Row + Column,TupleSequence
>::type
at() const
{
return seq.get<Columns * Row + Column>();
}
rc_matrix( TupleSequence const & s): seq(s){}
};
#include <iostream>
int main()
{
typedef boost::tuples::tuple<
double,quan::reciprocal_time::per_s,
quan::time::s,double
> matrix_elements;
rc_matrix<
2,2,
matrix_elements
>
mat(matrix_elements(2.,quan::reciprocal_time::per_s(3),quan::time::s(8),4.));
std::cout << mat.at<0,0>() << '\n';
std::cout << mat.at<0,1>() << '\n';
std::cout << mat.at<1,0>() << '\n';
std::cout << mat.at<1,1>() << '\n';
std::cout << mat.at<0,1>() * mat.at<1,0>() <<'\n';
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk