
Steve Clamage <Stephen.Clamage@Sun.COM> writes:
We recently corrected the way our compiler (Sun C++) handles static templates, and ran into a problem with some BOOST code. More than 100 tests in the suite depend on code like this:
template <typename T> struct S { void foo(int); };
template<class T , class U> static // static template ... void smart_cast_reference(U& u) {}
template <typename T> void S<T>::foo(int c) { smart_cast_reference< T& >(c); // used in global function }
int main() { S<int> s; s.foo(1); }
You can't use a static template in a global template function because it violates the One-Definition Rule, among possibly other rules. I have found that other compilers accept this code, but reject it when you put them in standard-conformning mode. (To see the rejection with some compilers, you need to build the executable.)
How critical to BOOST is this style of coding? Could the static templates be made global?
Steve, It really surprises me to hear that we have lots of this; it isn't a common idiom in Boost. Could you point us to some of the files where it's used? -- Dave Abrahams Boost Consulting www.boost-consulting.com