Boost logo

Boost :

From: jbandela_at_[hidden]
Date: 2001-06-06 00:25:36

Earlier in the discussions, there was talk about a typeof. This
inspired me to create my own TYPEOF implementations. It still
requires registering of types, but only the base types. It can then
handle template parameters, const, volatile, and references. Here is
an example that compiles in GCC 2.95.2

#include "Typeof.h"

#include <vector>
#include <iostream>

using namespace std;

// Some Types for testing
struct C0{};
template<class T> struct C1{};

template<class T1,class T2> struct C2{};

template<class T1,class T2,class T3> struct C3{};

template<class T1,class T2,class T3,class T4> struct C4{};


int main(){

        int i = 0;
        typedef std::vector<C4<C1<bool*>,double, C0,int > > Vec;
        Vec v;
        TYPEOF(v = Vec() ) d;
        v = d;
        // Uncomment below to see type in error message
        // i = d
        volatile const C4<C1<bool * const>,C2<const char*,void*>,
C0&,int >* c4;
        TYPEOF(c4) tc4;
        c4 = tc4;
        // Uncomment below to see type in error message
        // i = tc4;
        void***** p;
        TYPEOF(p) pp;
        p = pp;
        // Uncomment below to see type in error message
        // i = pp;
        TYPEOF(2.0 + 3) f;
        double g = f;
        // Uncomment below to see type in error message
        // int* h =f;


The only things previously registered were the primitive types(bool,
int, char, etc.). JRB_TYPEN specifies as type as taking N template
parameters. For example JRB_TYPE3(C3) means C3 is a template that
takes 3 class parameters.

The code is written in standard C++ (as much as I am aware of) and
can be found in the TYPEOF Folder in Files.

Let me know what you think.

John R. Bandela

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