|
Boost : |
Subject: Re: [boost] Library design Q : overloads v/s default args
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2010-06-20 10:21:14
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.
The attached file is automatically generated, and has a bunch of overloads for the syev template at the end, to handle parameters that benefit from "perfect forwarding" as well as handling the "Default workspace-type (optimal)". If I remember correctly, Rutger had reviewed Boost.Parameter first, before implementing the current solution. As some of the generated files were around ~10 MB in size, I recently wondered whether the techniques from Boost.Move (i.e. it's implementation of boost::forward) could help with this problem. However, I wasn't clever enough for this, so I gave up and instead tried to reduce the number of parameters that are considered for "perfect forwarding". I argued that only parameters corresponding to "vector arguments with general strides" or "matrix arguments" will likely be used with adapters, so that parameters corresponding to "normal vector arguments" could be excluded from "perfect forwarding" by default. Then I invented the name VectorView for "vector arguments with general strides", applied my changes and rejoiced when I noticed that the largest file was now ~100 kB in size.
But if there is a better solution, I'm curious to learn about it.
Regards,
Thomas
[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);".
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk