Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-02-27 23:36:22


--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> How would typeof() solve this problem? You can deduce the return
type, but
> we need a way to treat the entire wad of overloads for any given
name as a
> single runtime entity to be resolved only at the point of
invocation.
> Another important extension I hadn't thought of...
>
> -Dave

For the records, the solution to my problem works without boost::bind.
It involves a special functor for each function in <cmath>, e.g.:

> template <typename ResultType,
> typename ArgumentType>
> struct functor_acos {
> ResultType operator()(const ArgumentType& x) const {
> return ResultType(acos(x));
> }
> };

Here is how the functor is used (look for the ************,
shared<> is a reference-counted substitute for std::vector<>):

> template<typename ElementType>
> inline
> shared<
> typename unary_operator_traits<
> ElementType>::arithmetic>
> acos(const shared<ElementType>& a) {
> typedef shared<
> typename unary_operator_traits<
> ElementType>::arithmetic>
> result_array_type;
> typedef typename result_array_type::value_type
return_element_type;
> result_array_type result(a.size(), reserve_flag());
> // ************
> array_operation_unary(functor_acos<return_element_type,
ElementType>(),
> // ************
> a.begin(), result.begin(), a.size(),
> has_trivial_destructor<return_element_type>::value());
> result.set_size_back_door(a.size());
> return result;
> }

Thanks for all the help!
        Ralf


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