From: Paul S. <pau...@vi...> - 2006-10-04 11:58:50
|
Hi=20folks, This=20may=20be=20an=20obvious=20question,=20so=20forgive=20me=20if=20so. I've=20got=20a=20problem=20where=20I've=20written=20some=20(generic=20temp= lated)=20code taking=20a=20std::vector=20of=20vnl_vector_fixed: template<typename=20T,=20int=20N> void=20MyFunction(=20std::vector<vnl_vector_fixed<T,N>=20>=20&=20)=20=20{}= and=20the=20problem=20is=20that=20you=20can't=20pass=20a=20std::vector<vnl= _double_2>=20in=20to that=20function,=20because=20a=20vnl_double_2=20is=20not=20a=20typedef=20f= or vnl_vector_fixed<double,2>,=20and=20is=20instead=20its=20own=20class=20der= ived=20from vnl_vector_fixed<double,2>. Tthe=20purpose=20of=20the=20macro=20trickery=20in=20vnl_T_n.h=20seems=20to= =20be=20to=20only allow=20construction=20with=20the=20correct=20number=20of=20arguments,=20b= ut=20there=20are other=20ways=20of=20enforcing=20that=20at=20compile=20time=20(partial=20sp= ecialisation=20of the=20constructor=20-=20possible=20now=20that=20we=20don't=20support=20hig= hly non-compliant=20compilers=20like=20MSVC=206.0),=20and=20really=20simple=20= ways=20of checking=20that=20the=20right=20number=20of=20arguments=20have=20been=20fe= d=20in=20at=20run-time (although=20those=20might=20have=20a=20risk=20of=20side-effects). Also,=20vnl_matrix_fixed=20is=20a=20typedef,=20so=20there=20is=20an=20inco= nsistency. Have=20I=20got=20the=20reasoning=20for=20the=20macro=20stuff=20right,=20an= d=20could=20we=20replace it=20with=20a=20partially=20specialised=20constructor? Cheers,=20Paul. ________________________________________________________________________ This=20e-mail,=20and=20any=20attachment,=20is=20confidential.=20If=20you=20= have=20received=20it=20in=20error,=20do=20not=20use=20or=20disclose=20the=20= information=20in=20any=20way,=20notify=20me=20immediately,=20and=20please=20= delete=20it=20from=20your=20system. ________________________________________________________________________ |
From: Peter V. <pet...@ya...> - 2006-10-04 12:24:41
|
> Have I got the reasoning for the macro stuff right, and could we replace > it with a partially specialised constructor? I believe you're right (others please correct or add if necessary). We've (had) the policy, certainly in the core, to not use partial specialisation, to be able to support some compilers, and/or to simplify code maintenance. Maybe it's time to address this choice again. -- Peter. |
From: Amitha P. <pe...@cs...> - 2006-10-17 12:44:43
|
On Wed 04 Oct 2006, Peter Vanroose wrote: > We've (had) the policy, certainly in the core, to not use partial > specialisation, to be able to support some compilers, and/or to > simplify code maintenance. > > Maybe it's time to address this choice again. I agree. With the C++ standard now 8 years old, and with a good dashboard, I think we should revisit the choices of allowable C++ constructs in core. My own opinion is that the C++ allowed in the core should be the C++ intersection of the C++ accepted by all the compilers on the dashboard and by the 98 standard. Amitha. |
From: Brad K. <bra...@ki...> - 2006-10-17 13:18:40
|
Amitha Perera wrote: > On Wed 04 Oct 2006, Peter Vanroose wrote: >> We've (had) the policy, certainly in the core, to not use partial >> specialisation, to be able to support some compilers, and/or to >> simplify code maintenance. >> >> Maybe it's time to address this choice again. > > I agree. With the C++ standard now 8 years old, and with a good > dashboard, I think we should revisit the choices of allowable C++ > constructs in core. > > My own opinion is that the C++ allowed in the core should be the C++ > intersection of the C++ accepted by all the compilers on the dashboard > and by the 98 standard. FYI, this particular problem can be addressed in a way that still allows VS6 to work compile the code. See below for example code. The partial-spec block is probably the proper way to implement the constructors anyway. For the non-partial-spec version the vnl_vector_fixed_construct function is a template that initializes the data members using the arguments given. I'm pretty sure the template can be implemented in VS6. It won't restrict the user from providing the wrong number of arguments but code that compiles with the partial spec version will compile and work in VS6. -Brad template <class T, int n> class vnl_vector_fixed_impl { public: // ... most of current vnl_vector_fixed protected: T data_[n]; }; #if VCL_CAN_DO_PARTIAL_SPECIALIZATION template <class T, int n> class vnl_vector_fixed; template <class T> class vnl_vector_fixed<T, 2>: public vnl_vector_fixed_impl<T,2> { public: vnl_vector_fixed(T const& a1, T const& a2) { this->data_[0] = a1; this->data_[1] = a2; } }; //... other overloads #else template <class T, int n> class vnl_vector_fixed: public vnl_vector_fixed_impl<T,n> { public: vnl_vector_fixed(T const& a1, T const& a2) { vnl_vector_fixed_construct<T,n>(this->data_, a1, a2); } vnl_vector_fixed(T const& a1, T const& a2, T const& a3) { vnl_vector_fixed_construct<T,n>(this->data_, a1, a2, a3); } }; #endif typedef vnl_vector_fixed<double, 2> vnl_double_2; |