Boost logo

Boost :

Subject: Re: [boost] [non Boost] Template troubles.
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2008-12-10 13:55:00


Robert Jones wrote:
> On Wed, Dec 10, 2008 at 10:20 AM, Neil Groves <neil_at_[hidden]>wrote:
>
>> Neither of these are exact matches... is this deliberate? Or did you mean:
>>
>> template<typename T, std::size_t sz>
>> void assign(T (&assignee)[sz][sz], const T(&value)[sz][sz])
>> {
>> }
>>
>> I wondered this, because this modification makes it compile on Visual C++
>> because it is an exact match.
>>
>>
> Hi Neil
>
> Ultimately the signature you suggest is what I want to call, however I was
> hoping to achieve this via recursive instantiation, largely because looping
> over one index in the implementation is easily achieved with a for_each
> loop and a bind() call, whereas looping over two indices is rather
> cumbersome.

Didn't realize you'd also asked here (should pay more attention to
destinations). I think I gave you an idea why this is happening in my
response. As to doing it recursively:

template < typename T, size_t s >
void assign(T (&dest)[s][s], const T (&orig)[s][s])
{
   for (size_t i = 0; i < s; ++i) assign(dest[i], orig[i]);
}

should work...

untested.

As to extending this to arbitrary depth of arrays...you'll probably need
to use the boost preproc lib. I don't think even variadic templates
would help you here (and certainly wouldn't make it compile better in VS).

Note: adjusted the destinations so that everyone that's heard the
question has now heard the answers.


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