algorithm implementation 
Author Message
 algorithm implementation

Hi

Question for Dinkumware folks.

I noticed that on VS.NET's stl implementation, every stl's
algorithm that calls other functions (like sort calling
_Sort, which calls _Insertion_Sort sometimes), the
template parameters are not passed along.  

eg: std::sort's implementation is:

template<class _RanIt, class _Pr> inline
void sort(_RanIt _First, _RanIt _Last, _Pr _Pred){
        _Sort(_First, _Last, _Last - _First, _Pred);}

instead of:

template<class _RanIt, class _Pr> inline
void sort(_RanIt _First, _RanIt _Last, _Pr _Pred){
        _Sort<_RandIt,_Pr>(_First, _Last, _Last - _First,
_Pred);}

(ok, since there's "class _Diff" in the middle of _Sort's
template declaration, the above won't work, but you get
the point.)

Is there specific reason for this? Why let the compiler
deduce template arguments at each function call?

Specific problem: I tried to use std::sort<MyItr,
MyFunctor&>(..) to pass the functor by ref but it was
copied at _Sort(..)'s call since the explicit arguments
didn't make it to the second level.

Thanks,
Danny



Mon, 04 Apr 2005 12:05:11 GMT  
 algorithm implementation
Because VC.Net does not support class template partial specialization, it
use template function overloading as workaround. The additional parameter is
dedicated by compiler for chose right overloading version of function.


Quote:
> Hi

> Question for Dinkumware folks.

> I noticed that on VS.NET's stl implementation, every stl's
> algorithm that calls other functions (like sort calling
> _Sort, which calls _Insertion_Sort sometimes), the
> template parameters are not passed along.

> eg: std::sort's implementation is:

> template<class _RanIt, class _Pr> inline
> void sort(_RanIt _First, _RanIt _Last, _Pr _Pred){
> _Sort(_First, _Last, _Last - _First, _Pred);}

> instead of:

> template<class _RanIt, class _Pr> inline
> void sort(_RanIt _First, _RanIt _Last, _Pr _Pred){
> _Sort<_RandIt,_Pr>(_First, _Last, _Last - _First,
> _Pred);}

> (ok, since there's "class _Diff" in the middle of _Sort's
> template declaration, the above won't work, but you get
> the point.)

> Is there specific reason for this? Why let the compiler
> deduce template arguments at each function call?

> Specific problem: I tried to use std::sort<MyItr,
> MyFunctor&>(..) to pass the functor by ref but it was
> copied at _Sort(..)'s call since the explicit arguments
> didn't make it to the second level.

> Thanks,
> Danny



Wed, 13 Apr 2005 23:04:17 GMT  
 algorithm implementation

Quote:
>Because VC.net does not support class template partial

specialization,

But (correct me if I'm wrong) that's not partial template
specialization, just normal template use:

Quote:
> template<class _RanIt, class _Pr> inline
> void sort(_RanIt _First, _RanIt _Last, _Pr _Pred){
> _Sort<_RandIt,_Pr>(_First, _Last, _Last - _First,
> _Pred);}

danny


Thu, 14 Apr 2005 00:47:49 GMT  
 algorithm implementation
I think those function relies on iterator_traits in the STL code while the
compiler supports partial specialization. For VC.net, the iterator_traits
technique can not be adopted. And the function overloading will partly solve
the problem.

There must be somewhere in VC where using overloading as a workaround this
way, but I'm not very sure it is the point you point out. :-)


Quote:

> >Because VC.net does not support class template partial
> specialization,

> But (correct me if I'm wrong) that's not partial template
> specialization, just normal template use:

> > template<class _RanIt, class _Pr> inline
> > void sort(_RanIt _First, _RanIt _Last, _Pr _Pred){
> > _Sort<_RandIt,_Pr>(_First, _Last, _Last - _First,
> > _Pred);}

> danny



Thu, 14 Apr 2005 10:07:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. algorithm implementation

2. REQUEST: Optimal algorithm implementation for Page Faults in O.

3. Graph Algorithms Implementation ?

4. Optimizing the C implementation of RC5-32/12/16, an encryption algorithm

5. Algorithm for mining association rules implementation in C or C++

6. Looking for an implementation in C of Dijkstra's algorithm

7. Looking for implementation in C of Dijkstra's algorithm

8. Booth's algorithm C implementation

9. Boyer-Moore scan algorithm (C implementation)

10. **** looking for implementation of unification algorithm ****

11. Multiple levels of implementation and implementation inheritance

12. Help! I need C-implementation of algorithm Boyer-Moore search.

 

 
Powered by phpBB® Forum Software