|
Boost : |
From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-07-19 06:27:16
----- Original Message -----
From: "Gennadiy Rozental" <rogeeff_at_[hidden]>
> Page 6 1.3 : It seems that all_permutation could be implemented
shorter,
> something like this (not tested!)
>
> // return an array of the N! permutations of x
> template< typename T >
> wrapper< typename permutation_holder<T>::type >
> all_permutations(T const& in)
> {
> wrapper<typename permutation_holder<T>::type> result;
>
> unsigned const N = sizeof(T) / sizeof(**result.x);
> unsigned const result_size = sizeof(result.x) / sizeof(T);
> T* src = ∈ // (or &&*in?)
>
> for( T* dst = result.x; dst != result.x + result_size; ++dst )
> {
> std::copy(*src, *src + N, *dst);
> std::next_permutation(*dst, *dst + N);
> src = dst;
> }
> return result;
> }
Shortness wasn't the goal there. Furthermore, shortening by replacing
comments with untested code seemed ill-advised to me at the time <wink>.
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk