Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-06 12:59:37


On Mon, Oct 06, 2003 at 01:13:51AM -0700, Craigp wrote:
> VC71 complains that only integral constants can have a static
> initializer. The following seems to work:
>
> template <class T> struct container_element_name
> {
> static const char* name;
> };
>
> template <class T>
> const char* container_element_name<T>::name = "item";
...
> So assuming this is legal (it's ok to put the initializers in header
> files? Duplicate initialization via multiple includes isn't a problem?),
> this is perfect.

Yep, it's legal. (Just don't try to access the value of "name" before
main() gets called. If you need pre-main() access, switch to a static
method:
   static const char* name() { return "item"; }
or
   static const char* name() {
      static const char* x = "item";
      return x;
   }
The revised C++ language standard (I think) now says that the
order-of-intialization for static data members of templates is
undefined.)
      
> I was thinking about customizing some of the serialization logic (eg:
> removing the 'count' element), but then I wound up just writing an xslt
> script to transform the XML file into something the boost xml
> serialization library liked (except I still wanted a way to keep the
> element names the same).

Clever out-of-the-box solution. :)

-- 
-Brian McNamara (lorgon_at_[hidden])

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