help with metaprogramming

A

alessio211734

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

Alf P. Steinbach

* 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
 
V

Victor Bazarov

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
 
A

alessio211734

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

Victor Bazarov

[...]
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
 
S

Stuart Redmann

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top