Boost logo

Boost :

Subject: Re: [boost] Library design Q : overloads v/s default args
From: David Abrahams (dave_at_[hidden])
Date: 2010-06-20 11:00:06


At Sun, 20 Jun 2010 16:21:14 +0200,
Thomas Klimpel wrote:
>
> [1 <text/plain; us-ascii (quoted-printable)>]
> David Abrahams wrote:
> > Stefan Strasser wrote:
> > > > I am wondering if there is any reason to avoid default arguments in
> > > > general purpose libraries ?
> > >
> > > this case won't compile, template arguments are not deduced from
> > > default arguments.
> >
> > A problem, incidentally, that can be solved using Boost.Parameter.
>
> It depends, especially if "perfect forwarding" (see [1] why I use
> "...") of some parameters is also required.

Boost.Parameter does a very good approximation of perfect forwarding,
generating T&/T const& parameters for all out- and in/out- parameters.
It does erase rvalue-ness, but that's pretty much a given with C++03
that AFAICT nobody knows how to avoid.

> [1] It's not really about "perfect forwarding", but about capturing
> the non-const rvalue references. This is required for handling calls
> using adapters like "lapack::syev(bindings::lower(A), w);".

I'm just curious, Have you thought about using const rvalues as return
types in these situations? If you consider the adapter itself to be
immutable and the target sequence to be a separate object (which in
reality it is), it actually all makes sense. And a T const return
type will bind nicely to a generalized U& argument.

Cheers,

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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