The design of traits is as much art as anything else. There are no hard and fast answers here. I believe this question has gone unanswered because it is impossible to give a good answer without knowing a lot more about the problem you are solving In general traits classes are a useful "customization point".
That is, if you are designing a template: template class TileContainer { ... } TileContainer might make use of tile_traits> class TileContainer { // uses Traits } or: B) template class TileContainer { // uses tile_traits } There are examples of both designs in the C++03 and upcoming C++0x standards Example A designs: template, class Allocator = allocator> class basic_string; // both traits and Allocator are traits template > class wbuffer_convert; template > class vector; // Allocator is a A-trait that uses another // B-trait internally: allocator_traits template class basic_regex Example B designs: template struct iterator_traits; template struct allocator_traits; template struct pointer_traits; template struct treat_as_floating_point; template struct duration_values My only advice is that there is no right or wrong design. Use: template class TileContainer { // uses tile_traits } when you are sure that your customer's needs can always be met by specializing tile_traits class TileContainer { // uses Traits } when you suspect that your customer may need different traits for the same Tile, or when you want to force the type of TileContainer to be different when some trait other than tile_traits is used.
The design of traits is as much art as anything else. There are no hard and fast answers here. I believe this question has gone unanswered because it is impossible to give a good answer without knowing a lot more about the problem you are solving.In general traits classes are a useful "customization point".
That is, if you are designing a template: template class TileContainer { ... }; TileContainer might make use of tile_traits for some properties of Tile. And the client of TileContainer can specialize tile_traits in order to communicate variations of the properties when the default trait (if it exists) is not correct.So far I don't think I've said anything you don't already know (judging from the way your question is worded). I think your question is: Should you design: A) template class TileContainer { // uses Traits }; or: B) template class TileContainer { // uses tile_traits }; There are examples of both designs in the C++03 and upcoming C++0x standards.
Example A designs: template, class Allocator = allocator> class basic_string; // both traits and Allocator are traits template > class wbuffer_convert; template > class vector; // Allocator is a A-trait that uses another // B-trait internally: allocator_traits template class basic_regex; Example B designs: template struct iterator_traits; template struct allocator_traits; template struct pointer_traits; template struct treat_as_floating_point; template struct duration_values; My only advice is that there is no right or wrong design. Use: template class TileContainer { // uses tile_traits }; when you are sure that your customer's needs can always be met by specializing tile_traits. Use: template class TileContainer { // uses Traits }; when you suspect that your customer may need different traits for the same Tile, or when you want to force the type of TileContainer to be different when some trait other than tile_traits is used.
This pretty much sums up all my doubts about question #1. I think the answer to question #2 is, as you said, almost impossible to have a good answer for and is quite related more to the style, I think I can just go with what C++ Template Metaprogramming has to say about it for now – Khaled Nassar Feb 13 at 20:16.
Seeing you can provide default values for the traits, and having the traits parameter is always more flexible, I would choose this approach unless you have some specific reasons why you cannot do it. Template > class Foo {}.
Reading the question once more, I admit the answer is perhaps not related to it, as on second reading I do not really know what is this question about. It does not see to be related to the definition of the Foo templated class, only to the traits itself. There the answer is simple: when a ready-made traits suit you, use them, when not, provide your own.
– Suma Feb 13 at 16:29.
You need to have the traits class as a template parameter if you can see that people would pass different traits for the same data type. If your tiles will always have the same tile_traits for each T, you can use that directly. If you can see that someone, sometimes, will use a my_special_traits, you need to have that as a separate template parameter.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.