Multiple templates singletons
Hi,
I have a template class with 6 template arguments as :
template
Hello!
I have a question to this construct:
template
class TreeImplBase;
Each specialization of these holds a static std::map< boost::tuple
, const TreeImplBase* ; which contains the list of the derived template classes.
How can you instantiate a pointer to the class temlate? Class template is an incomplete type. You will not be able to specify a pointer to it. I think you should use boost::fusion inplace. This lib, offers a compile time map (if you map the same time to an instance of it, use a fusion set), which can map a type to an instance. This is what you need. http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/fusion/... http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/fusion/...
Any comments are appreciated,
Perhaps this is a known design pattern, perhaps there is an easier way of doing this, perhaps there is a boost library which helps with this,
Good Luck, Ovanes
Ovanes Markarian wrote:
Hello!
I have a question to this construct:
template
class TreeImplBase; Each specialization of these holds a static std::map< boost::tuple
, const TreeImplBase* >; which contains the list of the derived template classes. How can you instantiate a pointer to the class temlate? Class template is an incomplete type. You will not be able to specify a pointer to it.
The wording is a bit ambiguous: A pointer to an /incomplete type/ is in fact OK (using standard terminology), but 'TreeImplBase' is a /template id/ which is not a type at all. As Ovanes pointed out that construct is illegal, however (except inside a definition of 'TreeImplBase' where it's the /injected class name/). /Specializing/ a template with template arguments yields a type. Using (whatever) member of this type's interface causes the template to be implicitly (possibly partially) /instantiated/. It's most important to realize that specializing a template does not cause the template to be instantiated automatically. Note that "template specialization" has a context-dependent meaning, as it can either refer to a type or of a class (template) definition of a variant implementation of the template: // /primary template/ template< typename T > struct A { ... }; // definition of the (full) specialization A<int> template< > struct A<int> { ... }; // definition of a partial specialization template< typename T > struct A< B<T> > { typedef A self; // /injected class name/ is a type }; // X and Y are specializations (not instantiations)! typedef A< B<int> > X; typedef A< long > Y; int main() { X x; // instantiation of the 'B<int>'-specialization of A // at this point // ... OK, that's about template terminology in five minutes :-). Regards, Tobias
Tobias,
Thanks for your corrections. It is a bit difficult to speak by means of
"C++-Standard Language" ;)
With Kind Regards,
Ovanes
P.S.
---- OFFTOPIC
Could you take a look at my previous posting regarding singleton
destruction. May be you have overseen it.
---- END
On Jan 24, 2008 3:26 PM, Tobias Schwinger
The wording is a bit ambiguous: A pointer to an /incomplete type/ is in fact OK (using standard terminology), but 'TreeImplBase' is a /template id/ which is not a type at all.
As Ovanes pointed out that construct is illegal, however (except inside a definition of 'TreeImplBase' where it's the /injected class name/).
/Specializing/ a template with template arguments yields a type. Using (whatever) member of this type's interface causes the template to be implicitly (possibly partially) /instantiated/. It's most important to realize that specializing a template does not cause the template to be instantiated automatically.
Note that "template specialization" has a context-dependent meaning, as it can either refer to a type or of a class (template) definition of a variant implementation of the template:
// /primary template/ template< typename T > struct A { ... };
// definition of the (full) specialization A<int> template< > struct A<int> { ... };
// definition of a partial specialization template< typename T > struct A< B<T> > { typedef A self; // /injected class name/ is a type };
// X and Y are specializations (not instantiations)! typedef A< B<int> > X; typedef A< long > Y;
int main() { X x; // instantiation of the 'B<int>'-specialization of A // at this point
// ...
OK, that's about template terminology in five minutes :-).
Regards, Tobias
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ovanes Markarian wrote:
Tobias,
Thanks for your corrections. It is a bit difficult to speak by means of "C++-Standard Language" ;)
Yes. Good practice nevertheless, because both error messages and formal texts (not at least the standard itself) use this terminology ;-). Regards, Tobias
I'm attempting to use Boost.Fusion under Boost.Spirit.
I downloaded the library-only package as I already have boost 1.34.1 (which
includes spirit but not fusion)
However, under boost/spirit/fusion/, the structure of include dir is
different from the includes in the
http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/fusion/
quick_start.html
rds,
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Ovanes Markarian
Sent: 24 January 2008 15:52
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Multiple templates singletons
Tobias,
Thanks for your corrections. It is a bit difficult to speak by means of
"C++-Standard Language" ;)
With Kind Regards,
Ovanes
P.S.
---- OFFTOPIC
Could you take a look at my previous posting regarding singleton
destruction. May be you have overseen it.
---- END
On Jan 24, 2008 3:26 PM, Tobias Schwinger
boost fusion has been separated from the spirit library. In Spirit you find
the fusion 1.0.
This is the link to the original review message, from there you can get
separate fusion 2.0.
I don't know if smth. changed in the lib, but getting the head revision of
boost from subversion will provide you the latest sources of fusion:
http://lists.boost.org/boost-announce/2006/05/0088.php
Best Regards,
Ovanes
On Jan 25, 2008 6:47 PM, Hicham Mouline
I'm attempting to use Boost.Fusion under Boost.Spirit.
I downloaded the library-only package as I already have boost 1.34.1(which includes spirit but not fusion)
However, under boost/spirit/fusion/, the structure of include dir is different from the includes in the
http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/fusion/...
rds,
*From:* boost-users-bounces@lists.boost.org [mailto: boost-users-bounces@lists.boost.org] *On Behalf Of *Ovanes Markarian *Sent:* 24 January 2008 15:52 *To:* boost-users@lists.boost.org *Subject:* Re: [Boost-users] Multiple templates singletons
Tobias,
Thanks for your corrections. It is a bit difficult to speak by means of "C++-Standard Language" ;)
With Kind Regards, Ovanes
P.S. ---- OFFTOPIC Could you take a look at my previous posting regarding singleton destruction. May be you have overseen it. ---- END
On Jan 24, 2008 3:26 PM, Tobias Schwinger
wrote: [...] The wording is a bit ambiguous: A pointer to an /incomplete type/ is in fact OK (using standard terminology), but 'TreeImplBase' is a /template id/ which is not a type at all.
As Ovanes pointed out that construct is illegal, however (except inside a definition of 'TreeImplBase' where it's the /injected class name/).
/Specializing/ a template with template arguments yields a type. Using (whatever) member of this type's interface causes the template to be implicitly (possibly partially) /instantiated/. It's most important to realize that specializing a template does not cause the template to be instantiated automatically.
Note that "template specialization" has a context-dependent meaning, as it can either refer to a type or of a class (template) definition of a variant implementation of the template:
// /primary template/ template< typename T > struct A { ... };
// definition of the (full) specialization A<int> template< > struct A<int> { ... };
// definition of a partial specialization template< typename T > struct A< B<T> > { typedef A self; // /injected class name/ is a type };
// X and Y are specializations (not instantiations)! typedef A< B<int> > X; typedef A< long > Y;
int main() { X x; // instantiation of the 'B<int>'-specialization of A // at this point
// ...
OK, that's about template terminology in five minutes :-).
Regards, Tobias
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Hicham Mouline
-
Ovanes Markarian
-
Tobias Schwinger