Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-05-10 04:41:58


"David Abrahams" wrote...
> "Andy Little" writes:
>
>> "David Abrahams" wrote
>>> "Andy Little" writes:
>>>> FWIW I would prefer to live with BOOST_TYPEOF and type
>>>> registration. I have no doubt that registration will have its
>>>> problems but only by familiarity will they be solved.
>>>
>>> Huh? How will familiarity with the problem help? I can't ask my
>>> library's users to register types.
>>
>> Why not? We all want decltype and auto in the language dont we?
>> BOOST_TYPEOF is the closest we have. Show your users how to use it
>> while we wait for language support.
>
> Because I want to serve my users, not force them to learn about an
> interim solution that they won't need when the real feature comes out.

Not long to wait then, assuming upgrading is viable.... ;-)

Meanwhile I have found Boost.Typeof really useful now.

> Furthermore, it's _my_ library that needs result_of, so basically I
> would be telling users, "if you get a cryptic error message that looks
> like ___________, find some of the types in it and register them with
> this cryptic macro."

The error messages re lack of registration are not that bad IMO. The only
problems I had was deciding what types to register when using mpl::transform
IIRC.

> I'd rather that people enjoy my library than
> have them vent frustration at me about how unusable Boost is.

The last time I tried to use lambda I seem to remember I had to do a lot more
than just register my types with one cryptic macro.
 I had to map my own whacky type deduction scheme to lambdas whacky type
deduction scheme. See below --^-->

It would be nice if in future I registered my types once with Boost.Typeof , and
then they work with lambda and any other library out of the box.

Note: That would be nice in theory, but it seems that gcc has problems using
expressions in return types, so maybe that leaves us back where we started,..
except that whatever type deduction wrapper is used it could then be implemented
using Boost.Typeof.

regards
Andy Little

--------------- **registering** with lambda
http://www.boost.org/doc/html/lambda/extending.html

(note this is from a previous version of pqs)

#ifndef PQS_BOOST_LAMBDA_INTERFACE_HPP_INCLUDED
#define PQS_BOOST_LAMBDA_INTERFACE_HPP_INCLUDED

// Copyright (C) Andy Little 2004.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.

#include "pqs/ct_quantity/ct_quantity_fwd.hpp"
#include "pqs/operators/binary_operator_functors.hpp"
#include "boost/lambda/lambda.hpp"

namespace pqs{

    template< typename Op>
    struct lambda_binary_operation_key;

    template<>
    struct lambda_binary_operation_key<
        boost::lambda::other_action<
            boost::lambda::assignment_action
>
>{
        typedef pqs::operator_equals type;
    };

    template<>
    struct lambda_binary_operation_key<
        boost::lambda::arithmetic_action<
            boost::lambda::plus_action
>
>{
        typedef pqs::operator_plus type;
    };
// for stream output
    template<>
    struct lambda_binary_operation_key<
        boost::lambda::bitwise_action<
            boost::lambda::leftshift_action
>
>{
        typedef pqs::operator_shift_left type;
    };

    template<>
    struct lambda_binary_operation_key<
        boost::lambda::arithmetic_action<
            boost::lambda::minus_action
>
>{
        typedef pqs::operator_minus type;
    };

    template<>
    struct lambda_binary_operation_key<
        boost::lambda::arithmetic_action<
            boost::lambda::multiply_action
>
>{
        typedef pqs::operator_multiplies type;
    };

    template<>
    struct lambda_binary_operation_key<
        boost::lambda::arithmetic_action<
            boost::lambda::divide_action
>
>{
        typedef pqs::operator_divides type;
    };
}

namespace boost{namespace lambda{

    template<
        typename Op,
        typename NamedAbstractQuantity,
        typename QuantityUnit,
        typename Value_type,
        typename Other
>
    struct plain_return_type_2<
        Op,
        pqs::ct_quantity<NamedAbstractQuantity,QuantityUnit,Value_type>,
        Other
>{
        typedef typename pqs::lambda_binary_operation_key<
            Op
>::type pqs_operator_type;
        typedef typename pqs_operator_type
        ::template result<
            pqs_operator_type(
            pqs::ct_quantity<NamedAbstractQuantity,QuantityUnit,Value_type>,
            Other)
>::type type;
    };

    template<
        typename Op,
        typename Other,
        typename NamedAbstractQuantity,
        typename QuantityUnit,
        typename Value_type
>
    struct plain_return_type_2<
        Op,
        Other,
        pqs::ct_quantity<NamedAbstractQuantity,QuantityUnit,Value_type>

>{
        typedef typename pqs::lambda_binary_operation_key<
            Op
>::type pqs_operator_type;
        typedef typename pqs_operator_type
        ::template result<
            pqs_operator_type(
            Other,
            pqs::ct_quantity<NamedAbstractQuantity,QuantityUnit,Value_type>)
>::type type;
    };

    template<
        typename Op,
        typename Abstract_idL,
        typename QuantityUnitL,
        typename Value_typeL,
        typename Abstract_idR,
        typename QuantityUnitR,
        typename Value_typeR
>
    struct plain_return_type_2<
        Op,
        pqs::ct_quantity<Abstract_idL,QuantityUnitL,Value_typeL>,
        pqs::ct_quantity<Abstract_idR,QuantityUnitR,Value_typeR>
>{
        typedef typename pqs::lambda_binary_operation_key<
            Op
>::type pqs_operator_type;
        typedef typename pqs_operator_type
        ::template result<
            pqs_operator_type(
            pqs::ct_quantity<Abstract_idL,QuantityUnitL,Value_typeL>,
            pqs::ct_quantity<Abstract_idR,QuantityUnitR,Value_typeR>)
>::type type;
    };

}}//boost::lambda

#endif


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk