|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-02-05 03:47:23
Terje Slettebø wrote:
>>>By the way, just for fun. Adding the following output operator for
>
> arrays,
>
>>>to the header I gave in the previous posting:
>>
>>>-------
>>>|O|X|O|
>>>-------
>>>|X|X|O|
>>>-------
>>>|O|O|X|
>>>-------
>>>
>>>"Shall we play a game?" :)
>>
>>Sure thing :-)
>
>
> I guess you maybe got the "War Games" reference? :)
Don't know what this reference is, but played that game in school.
>>2. I think that we better have separate headers for stl containers, like
>> suggested in my original email (<boost/io/vector.hpp>, etc). That's
>> because I'd like to output maps, but would not like to include <map>
>> when I need to output a vector.
>
>
> Heh, just before I got this posting, I had added the following comment in
> the header:
[...]
We're in total agreement until now.
> I'll get back to your other comments, I just need to look more into
> how it might be done.
Maybe you know a better solution already, but thinking about per-conainer
format is arrive to:
We basically need the following (note that "..." are no metacharacters)
template<class charT, template <...> class container>
class basic_composite_io {
int get_pword_index();
}
template<class charT>
int basic_composite_io<charT, vector<...> >::get_pword_index() {
static int i = ios_base::xalloc();
return i;
}
Since we can specialize on template name, we have to fake that:
template<class charT, class T, class A>
int basic_composite_io<charT, vector<T, A> >::get_pword_index() {
static int i = get_vector_pword_index();
return i;
}
Why can't we afford to create a function for each supported container,
make it call xalloc, and return that value. Not very nice, but works.
Another alternative is to create custom 'xalloc' which takes a string,
and does not allocate new index if an index for that string is already
allocated.
template<class charT, class T, class A>
int basic_composite_io<charT, vector<T, A> >::get_pword_index() {
static int i = xalloc("std::vector");
return i;
}
Would this be sufficient?
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk