Is this a partial specialization issue?

Discussion in 'C++' started by Steven T. Hatton, May 22, 2004.

  1. The subject of templates in C++ is still a weak point for me. If I had
    slept in the past 24 hours, I might be able to figure this out myself,
    nonetheless, I'll go ahead and ask.

    I'm trying to create a type which is formed of a boost::array of
    boost::arrays of boost::arrays of 3 float elements. The table below
    demonstrates the idea. Assume x, y and z are float:

    vf[x, y, z][1, 1] vf[x, y, z][1, 2] vf[x, y, z][1, 3] vf[x, y, z][1, 4]

    vf[x, y, z][2, 1] vf[x, y, z][2, 2] vf[x, y, z][2, 3] vf[x, y, z][2, 4]

    vf[x, y, z][3, 1] vf[x, y, z][3, 2] vf[x, y, z][3, 3] vf[x, y, z][3, 4]

    vf[x, y, z][4, 1] vf[x, y, z][4, 2] vf[x, y, z][4, 3] vf[x, y, z][4, 4]

    vf[x, y, z][5, 1] vf[x, y, z][5, 2] vf[x, y, z][5, 3] vf[x, y, z][5, 4]


    I want to be able to specify the size when the object is instantiated. The
    following results in an error when I try to compile it:

    typedef array<float,3> Vec3f;
    typedef array<Vec3f> Field3f;

    It says mean things such as:

    /**************************************************************/
    In file included
    from /home/hattons/code/c++/gs/vertices/src/vertexfield.cpp:20:
    /home/hattons/code/c++/gs/vertices/src/vertexfield.h:27: error: wrong number
    of
    template arguments (1, should be 2)
    /home/hattons/opt/org/boost/include/boost-1_31/boost/array.hpp:38: error:
    provided
    for `template<class T, unsigned int N> class boost::array'
    /**************************************************************/

    My compiler is quite pleased with this:
    using boost::array;
    typedef array<float,3> Vec3f;
    const unsigned N=5;
    typedef array<Vec3f, N> Field3f;

    Is there a way I can create something that acts like a type definition that
    accepts a const unsigned when I'm ready to provide it?



    --
    STH
    Hatton's Law: "There is only One inviolable Law"
    KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
    Mozilla: http://www.mozilla.org
    Steven T. Hatton, May 22, 2004
    #1
    1. Advertising

  2. "Steven T. Hatton" <> wrote in message
    news:...
    > The subject of templates in C++ is still a weak point for me. If I had
    > slept in the past 24 hours, I might be able to figure this out myself,
    > nonetheless, I'll go ahead and ask.
    >
    > I'm trying to create a type which is formed of a boost::array of
    > boost::arrays of boost::arrays of 3 float elements. The table below
    > demonstrates the idea. Assume x, y and z are float:
    >
    > vf[x, y, z][1, 1] vf[x, y, z][1, 2] vf[x, y, z][1, 3] vf[x, y, z][1, 4]
    >
    > vf[x, y, z][2, 1] vf[x, y, z][2, 2] vf[x, y, z][2, 3] vf[x, y, z][2, 4]
    >
    > vf[x, y, z][3, 1] vf[x, y, z][3, 2] vf[x, y, z][3, 3] vf[x, y, z][3, 4]
    >
    > vf[x, y, z][4, 1] vf[x, y, z][4, 2] vf[x, y, z][4, 3] vf[x, y, z][4, 4]
    >
    > vf[x, y, z][5, 1] vf[x, y, z][5, 2] vf[x, y, z][5, 3] vf[x, y, z][5, 4]
    >
    >
    > I want to be able to specify the size when the object is instantiated.

    The
    > following results in an error when I try to compile it:
    >
    > typedef array<float,3> Vec3f;
    > typedef array<Vec3f> Field3f;
    >
    > It says mean things such as:
    >
    > /**************************************************************/
    > In file included
    > from /home/hattons/code/c++/gs/vertices/src/vertexfield.cpp:20:
    > /home/hattons/code/c++/gs/vertices/src/vertexfield.h:27: error: wrong

    number
    > of
    > template arguments (1, should be 2)
    > /home/hattons/opt/org/boost/include/boost-1_31/boost/array.hpp:38: error:
    > provided
    > for `template<class T, unsigned int N> class boost::array'
    > /**************************************************************/
    >
    > My compiler is quite pleased with this:
    > using boost::array;
    > typedef array<float,3> Vec3f;
    > const unsigned N=5;
    > typedef array<Vec3f, N> Field3f;
    >
    > Is there a way I can create something that acts like a type definition

    that
    > accepts a const unsigned when I'm ready to provide it?
    >


    Templated typedef's are one of the things C++ ought to have but doesn't.
    This is illegal

    template <unsigned N>
    typedef array<Vec3f, N> Field3f;

    Field3f<10> a_field_of_ten_vectors;


    I think they'll be added one day but for now, you must wrap the typedef
    inside a templated class.

    template <unsigned N>
    struct Field
    {
    typedef Field3f<N> type;
    };

    Field<10>::type a_field_of_ten_vectors;

    john
    John Harrison, May 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chandra Shekhar Kumar

    template partial specialization

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    17
    Views:
    3,028
    tom_usenet
    Jun 25, 2003
  2. Philip Lawatsch

    Partial Specialization workaround

    Philip Lawatsch, Jul 16, 2003, in forum: C++
    Replies:
    9
    Views:
    394
    Philip Lawatsch
    Jul 16, 2003
  3. Alexander Stippler

    partial specialization of function template

    Alexander Stippler, Aug 15, 2003, in forum: C++
    Replies:
    1
    Views:
    551
    Rob Williscroft
    Aug 15, 2003
  4. Petre Iantu
    Replies:
    1
    Views:
    352
    Petre Iantu
    Aug 17, 2003
  5. Joseph Turian
    Replies:
    2
    Views:
    464
Loading...

Share This Page