Boost logo

Boost :

From: Michael Stevens (Michael.Stevens_at_[hidden])
Date: 2003-02-06 07:05:23

Just ran into a problem using utility::base_from_member. The problem
occurs in the forwarding of constructor arguments to the 'member'. The
base_from_member get these arguments using pass by value.

 From the implementation we have:

    template< typename T1 >
    explicit base_from_member( T1 x1 )
        : member( x1 )

I would suggest changing this to pass by reference, that is:

    template< typename T1 >
    explicit base_from_member( const T1& x1 )
        : member( x1 )

There seem to be several good reasons for changing to pass by reference:
1. It is more transparent to the 'member'.
The pass by value in the base_from_member constructor copies it
arguments before 'member' sees them. The actual parameter passed to
'member' is a temporay. If 'member' is actual storing a reference to
argument, the reference will be to the temporary and will thus fail.

2. The additional copy put additional requirements on 'members'
arguments types. They may not actually be copiable!

3. The runtime cost of the copy.

Hopefully there are no disadvanatage!

Michael Stevens

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