help with metaprogramming

Discussion in 'C++' started by alessio211734, May 18, 2010.

  1. I would like understand this class TriMesh defined in
    https://vcg.svn.sourceforge.net/svnroot/vcg/trunk/vcglib/vcg/complex/trimesh/base.h

    I think the implementation is a metaprogramming trick and I ask you
    for some help to understand it.


    From this tutorials
    http://vcg.sourceforge.net/index.php/Tutorial

    explains I can declare:

    class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>,
    std::vector<MyFace> > {}
    or
    class MyMesh : public vcg::tri::TriMesh<
    std::vector<MyFace> ,std::vector<MyVertex>,std::vector<MyEdge> > {}

    and the difference is that in the first declaration I have a trimesh
    with vertex and face while in the second declaration I have a trimesh
    with face, vertex and edge.

    Can anyone explain me where can I study this metaprogramming trick to
    understand the triMesh class implementation?


    Thanks in advance.
    alessio211734, May 18, 2010
    #1
    1. Advertising

  2. * alessio211734, on 18.05.2010 12:43:
    > I would like understand this class TriMesh defined in
    > https://vcg.svn.sourceforge.net/svnroot/vcg/trunk/vcglib/vcg/complex/trimesh/base.h
    >
    > I think the implementation is a metaprogramming trick and I ask you
    > for some help to understand it.
    >
    >
    > From this tutorials
    > http://vcg.sourceforge.net/index.php/Tutorial
    >
    > explains I can declare:
    >
    > class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>,
    > std::vector<MyFace> > {}
    > or
    > class MyMesh : public vcg::tri::TriMesh<
    > std::vector<MyFace> ,std::vector<MyVertex>,std::vector<MyEdge> > {}
    >
    > and the difference is that in the first declaration I have a trimesh
    > with vertex and face while in the second declaration I have a trimesh
    > with face, vertex and edge.
    >
    > Can anyone explain me where can I study this metaprogramming trick to
    > understand the triMesh class implementation?


    You haven't shown what it is that you don't understand.


    Cheers & hth.,

    - Alf


    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach, May 18, 2010
    #2
    1. Advertising

  3. On 5/18/2010 6:43 AM, alessio211734 wrote:
    > I would like understand this class TriMesh defined in
    > https://vcg.svn.sourceforge.net/svnroot/vcg/trunk/vcglib/vcg/complex/trimesh/base.h
    >
    > I think the implementation is a metaprogramming trick and I ask you
    > for some help to understand it.
    >
    >
    > From this tutorials
    > http://vcg.sourceforge.net/index.php/Tutorial
    >
    > explains I can declare:
    >
    > class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>,
    > std::vector<MyFace> > {}
    > or
    > class MyMesh : public vcg::tri::TriMesh<
    > std::vector<MyFace> ,std::vector<MyVertex>,std::vector<MyEdge> > {}
    >
    > and the difference is that in the first declaration I have a trimesh
    > with vertex and face while in the second declaration I have a trimesh
    > with face, vertex and edge.
    >
    > Can anyone explain me where can I study this metaprogramming trick to
    > understand the triMesh class implementation?


    How about the actual headers in which TriMesh is defined? Have you
    tried just looking at the definition? There are often clues in the
    source code...


    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, May 18, 2010
    #3
  4. template < class Container0 = DummyContainer, class Container1 =
    DummyContainer, class Container2 = DummyContainer, class Container3 =
    DummyContainer >
    class TriMesh
    : public MArity3< BaseMeshTypeHolder<typename
    Container0::value_type::TypesPool>, Container0, Der ,Container1, Der,
    Container2, Der/*, Container3, Der*/>{
    public:

    for example I have problem to understand this template syntax...

    or this one template syntax

    https://vcg.svn.sourceforge.net/svnroot/vcg/trunk/vcglib/vcg/container/derivation_chain.h

    template <
    class Base,
    template <typename> class A, template <typename> class B,
    template <typename> class C, template <typename> class D,
    template <typename> class E, template <typename> class F,
    template <typename> class G, template <typename> class H,
    template <typename> class I, template <typename> class J,
    template <typename> class K>
    class Arity11: public K<Arity10<Base, A, B, C, D, E, F, G, H, I,
    J> > {};


    template <
    class Base,
    template <typename> class A, template <typename> class B,
    template <typename> class C, template <typename> class D,
    template <typename> class E, template <typename> class F,
    template <typename> class G, template <typename> class H,
    template <typename> class I, template <typename> class J,
    template <typename> class K, template <typename> class L>
    class Arity12: public L<Arity11<Base, A, B, C, D, E, F, G, H, I,
    J, K> > {};

    I see nested template and I don't know how they work. Can you suggest
    me a link where I can study this syntax. Thanks.
    alessio211734, May 18, 2010
    #4
  5. On 5/18/2010 8:15 AM, alessio211734 wrote:
    >[...]
    > I see nested template and I don't know how they work. Can you suggest
    > me a link where I can study this syntax. Thanks.


    Without knowing your experience with non-template part of the language,
    it's kind of like throwing spaghetti at a wall, but try the "C++
    Templates" book by Vandevoorde and Josuttis. Very systematic and quite
    complete. And try to get in the habit of studying using books, not links.

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, May 18, 2010
    #5
  6. On 18 Mai, 14:15, alessio211734 <> wrote:

    > for example I have problem to understand this template syntax...
    >
    > template < class Container0 = DummyContainer, class Container1 =
    > DummyContainer, class Container2 = DummyContainer, class Container3 =
    > DummyContainer >
    > class TriMesh
    >                 : public  MArity3<   BaseMeshTypeHolder<typename
    > Container0::value_type::TypesPool>, Container0, Der ,Container1, Der,
    > Container2, Der/*, Container3, Der*/>{
    >         public:


    [snip]

    > I see nested template and I don't know how they work. Can you suggest
    > me a link where I can study this syntax. Thanks.


    I suppose that you just want to use this library, so you should not
    worry about the internals of the templates (personally, I hate it to
    use some template-ridden library where one gets the most cryptic error
    message if one forgot to end a simple statement with a semi-colon),
    just stick to what the tutorials of the library say.

    If your library doc says that
    class MyMesh :
    public vcg::tri::TriMesh< std::vector<MyVertex>,
    std::vector<MyFace> > {}

    defines a mesh with vertex and face, while

    class MyMesh :
    public vcg::tri::TriMesh< std::vector<MyFace>,
    std::vector<MyVertex>,
    std::vector<MyEdge> > {}

    defines a mesh with face, vertex and edge, then so be it. However,
    after a glance into the svn repository of VCGLib, you're probably up
    to your neck in s**t because the source code seems to be in very poor
    condition (next to no comments, unintelligible comments, commented
    code, ...) for a library that relies a lot on templates (in my
    experience template code needs at least twice the amount of
    documentation, about 70% comments, 30% code).

    Good luck,
    Stuart
    Stuart Redmann, May 19, 2010
    #6
    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. Dave
    Replies:
    0
    Views:
    598
  2. Dave
    Replies:
    12
    Views:
    566
    Mike Hewson
    Dec 26, 2003
  3. Sarah Thompson
    Replies:
    2
    Views:
    367
    Sumit Rajan
    Apr 23, 2004
  4. Chris Richards

    Metaprogramming help

    Chris Richards, Nov 26, 2007, in forum: Ruby
    Replies:
    8
    Views:
    93
    Trans
    Nov 27, 2007
  5. Dhaval
    Replies:
    5
    Views:
    90
    Brian Candler
    Nov 16, 2009
Loading...

Share This Page