Boost logo

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
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.

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
    at() const
        return seq.get<Columns * Row + Column>();
    rc_matrix( TupleSequence const & s): seq(s){}

#include <iostream>
int main()
    typedef boost::tuples::tuple<
> matrix_elements;
    std::cout <<<0,0>() << '\n';
    std::cout <<<0,1>() << '\n';
    std::cout <<<1,0>() << '\n';
    std::cout <<<1,1>() << '\n';

    std::cout <<<0,1>() *<1,0>() <<'\n';


Boost list run by bdawes at, gregod at, cpdaniel at, john at