|
Boost : |
From: Andy Little (andy_at_[hidden])
Date: 2006-09-28 21:15:56
"Douglas Gregor" <doug.gregor_at_[hidden]> wrote in message
news:6F743D04-2F34-488D-BBC6-0DEC80DBCBC2_at_osl.iu.edu...
OK. Thanks for sorting that out.
FWIW here is my user impressions from the tutorial. I suspect that maybe other
people trying this out will get into these difficulties, once they start
experimenting. In this situation,
being human and seeing nothing wrong with my code which (I hope) would have
always worked before, I immediately suspect the compiler. Lets face it hacking
Gcc is a no no anyway. Its new , why shouldnt it be full of bugs? So that is a
hurdle.
For that reason I think the tutorial example is way too complicated:
double sum(double array[], int n)
{
double result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
There is way too much going on here IMO.
I eventually started with this:
auto concept Addable<typename T1, typename T2> {
typename result_type;
result_type operator+(T1 x, T2 y);
};
template <typename TL, typename TR>
where Addable<TL,TR>
Addable<TL,TR>::result_type
add( TL const & lhs, TR const & rhs)
{
return lhs + rhs;
}
And then to this:
auto concept Assignable<typename T1, typename T2> {
T1& operator=(T1& x, T2 y);
};
template <typename TL,typename TR>
where Addable<TL,TR> && Assignable<TL,Addable<TL,TR>::result_type >
TL& add_assign( TL & lhs, TR const & rhs)
{
lhs = lhs + rhs;
return lhs;
}
Maybe that is related to my stuff though. Anyway it might be worth trying to cut
extraneous stuff from the first example.
Secondly, the way templates currently work is firmly entrenched in my brain.
Currently they work most of the time, with any old junk that you throw at them.
Maybe you need to stress that although the syntax is similar, that once you
include Concept features that your template parameters are suddenly imbued with
a much different character. This relates a lot to the first point; If it doesnt
work then (often wrongly but nevertheless... )suspect the compiler.
in the words of Spock in Start Trek. "This is C++ Jim, but not as we know it."
I'll have to think more about it.
Anyway I definitely want to spend some time learning more about it and try to
port my physical quantities stuff over. Its a really clean way of doing things.
I love it ! trouble is there is a lot going on in C++ at the moment, so there is
no way I am going to master all this for a while.
regards
Andy Little
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk