Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-06-21 16:37:08

Herve Bronnimann wrote:
> I was going to make the same suggestion! If the purpose of identity is
> top be a metafunction, or a function on types, then type_ is
> the natural prefix.

To some extent purpose of everything in boost::mpl is to be a metafunction
:), so the argument doesn't really hold.

> I would favor giving just a single class (not two) and as a result
> getting rid of the difference in interface between the class template
> and its specialization (which could be evil in some cases):
> template <class T>
> struct identity
> : std::unary_function<T,T> // defines argument_type, result_type
> {
> typedef T type; // somewhat redundant with unary_function,
> // but apparently to satisfy mpl's interface
> template <class U> struct rebind { typedef identity<U>
> other; };
> T operator()(T x) const { return x; }
> };

'rebind' is not needed here. That's more, if you _really_ want something
useful in contemporary world of C++ "runtime" functional programming, then
the return type typedef should be probable spelled as

    template<typename SigArgs> struct sig { typedef T type; }; // Lambda


    template<typename T> struct result { typedef T type; }; // Phoenix

and, in the latter case, may be the whole thing should be written as

    struct identity
        template< typename T > struct result { typedef T type; };

        template< typename T >
        T operator()(T x) const { return x; }

In any case, until we have a solid understanding of how a standard interface
of runtime function object should look like, and how it should interact with
compile-time metafunction protocol, and if the differences are small enough
for common code base to be worth pursuing, I am somewhat opposite to the
idea of stuffing the current 'boost::mpl::identity<>' with features of
uncertain utility (like 'operator()' and 'std::*nary_function' typedefs).


Boost list run by bdawes at, gregod at, cpdaniel at, john at