Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-04-20 05:07:31


"Thorsten Ottosen" wrote
> Andy Little wrote:
>> I dont understand the char_type member typedef of the traits class. The
>> functions that use it all seeem to be free functions which could change from
>> e.g
>>
>> template<class Ptree>
>> void read_xml(std::basic_istream<typename Ptree::char_type> &stream,
>> Ptree &pt,
>> int flags = 0);
>>
>> to
>>
>> template<class Ptree, class Char>
>> void read_xml(std::basic_istream<Char> &stream, Ptree &pt,int flags = 0);
>>
>> without problems. That would remove one level of coupling wouldnt it?
>
> I'm not sure it is worth speculating too much about coupling. The
> function will implicitly depend on the interface of basic_ptree<>
> anyway. So there is no reason to hide that fact.

The only resaon for the char_type traits parameter is for stream I/O though isnt
it? IOW because of this coupling each ptree type can only be serialised to a
stream parameterised on one char type. You cannot therefore have a wide string
ptree loaded from a char file for example.

> I consider this interface most elegant (because ADL also works):
>
> namespace boost
> {
> template< class Traits >
> void read_xml( std::basic_istream<typename Traits::char_type>& str,
> basic_ptree<Traits>& tree,
> int flags = 0 );
> }

ADL also works ...

 namespace boost
 {
  template< class Traits , typename Char>
   void read_xml( std::basic_istream<Char>& str,
                 basic_ptree<Traits>& tree,
                  int flags = 0 );
 }

regards
Andy Little


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk