|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2004-04-02 16:28:26
From: "Andy Little" <andy_at_[hidden]>
>
> But is it the flexibility that se wants.
^^
I try to use "s/he" for that. "se" just looks like a typo.
> #include <iostream>
> template< typename A , typename B >
> struct multiply_traits;
>
> // use traits
> template< typename A , typename B >
> struct multiply1{
>
> typedef multiply_traits<A,B> traits;
> typename traits::result_type operator ()
> (typename traits::first_argument_type a,
> typename traits::second_argument_type b)
> {
> return a * b;
> }
>
> };
template< typename A, typename B >
class multiply1
{
typedef multiply_traits<A,B> traits;
public:
typedef typename traits::result_type result_type;
typedef typename traits::first_argument_type first_argument_type;
typedef typename traits::second_argument_type second_argument_type;
result_type
operator()(first_argument_type a, second_argument_type b)
{
return a * b;
}
};
> //use policy
> template< typename A , typename B, typename Policy>
> struct multiply2{
>
> typename Policy::result_type operator ()
> (typename Policy::first_argument_type a,
> typename Policy::second_argument_type b)
> {
> return a * b;
> }
>
> // or Policy ()(a,b); etc if ---> policy
>
> };
template< typename A, typename B, class Policy >
struct multiply2 : Policy
{
};
> template<typename T>
> struct multiply_traits<T,T>{
> typedef T result_type;
> typedef T first_argument_type;
> typedef T second_argument_type;
> //operator()(a,b) etc if --->policy
> };
>
> int main()
> {
> multiply1<int,int>::traits::result_type val1
multiply1<int,int>::result_type val1
> = multiply1<int,int>()(10,10);
> std::cout << val1 <<'\n';
>
> multiply_traits<int,int>::result_type val2
> = multiply2<int,int,multiply_traits<int,int> >()(10,10);
typedef multiply2< int, int, multiply_traits< int, int > > m2;
m2::result_type val2(m2()(10, 10));
> std::cout << val2 <<'\n';
> }
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk