help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how does template<template<...> op> function(op<...>) work?


From: Piotr Sawuk
Subject: Re: how does template<template<...> op> function(op<...>) work?
Date: 19 Aug 2007 21:33:27 GMT

In article <mailman.4795.1187138603.32220.help-gplusplus@gnu.org>,
        "John V. Shahid" <jvshahid@gmail.com> writes:
> Sorry for not reading your message, but I was busy lately. I think the
> reason no one responded to you is that the code you submitted is either
> not compilable or not complete.

of course it's not compileable, that was my point. however,you're right,
I simply removed unneccessary code and thereby the result got crippled.
I forgot 1 include and the default-parameter as you noticed. however,
recently I got an

internal compiler error: in instantiate_class_template, at cp/pt.c:5666

after replacing below my complicated operator= version with the much simpler
(or even adding the following to stl_algorithm_class):

        template<template<class,typename> class stl_operator_,
                 class op_, typename val2_>
        iter_ operator=(stl_operator_<op_,val2_>& o)
        {return o(*this);}

Please submit the bug-report yourself, since I don't have net-access now.
So, again, my original question was about

error: no match for 'operator=' in 'o =...

when compiling (with g++ 4.1.2):

#include <algorithm>
#include <functional>

template<typename iter_, typename val_=
                typename std::iterator_traits<iter_>::value_type>
struct stl_algorithm_class
{//class encapsulating all stl-algorithms operating on iterator-ranges...
    template<class op_,typename iter2_=iter_>
    class stl_binary_operation
    {
        stl_algorithm_class<iter_> v1;
        stl_algorithm_class<iter2_> v2;
                public:
        stl_binary_operation(stl_algorithm_class<iter_> v,
                             stl_algorithm_class<iter2_> w): v1(v), v2(w) {}
        template<typename iter3_>
        iter3_ operator()(stl_algorithm_class<iter3_> o)
        {return std::transform(v1.start,v1.tail,v2.start,o.start, op_());}
    };
    template<class op_,typename iter2_>
    class stl_unary_operation
    {//similar
    };

    iter_ start,tail;
    stl_algorithm_class(const iter_& s, const iter_& e): start(s), tail(e) {}

    template<typename iter2_,typename val2_>
    iter_ operator=(const stl_algorithm_class<iter2_,val2_>& t)
    {return std::copy(t.start,t.tail,start);}
    template<template<class,typename> class stl_operator_,class iter2_,
             typename val1_,class op_, typename val2_>
    iter_ operator=(typename stl_algorithm_class<iter2_,val1_>::template
                                           stl_operator_<op_,val2_>& o)
    {return o(*this);}
        
        
    template<typename iter2_>
    friend stl_binary_operation<std::multiplies<val_>,iter2_ > 
            operator*(const stl_algorithm_class<iter_>& a,
                      const stl_algorithm_class<iter2_>& b)
    {return stl_binary_operation<std::multiplies<val_> ,iter2_>(a,b);}
};

int n(16),s1[16],s2[16];
stl_algorithm_class<int*,int> i(s1,s1+n),o(s2,s2+n);

int main()
{
        o=o*i;
}

-- 
Better send the eMails to netscape.net, as to
evade useless burthening of my provider's /dev/null...

P


reply via email to

[Prev in Thread] Current Thread [Next in Thread]