$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Ronald Garcia (garcia_at_[hidden])
Date: 2008-07-04 11:42:00
On Jun 30, 2008, at 9:46 AM, Joey Mukherjee wrote:
>
> On Jun 27, 2008, at 11:16 AM, Ronald Garcia wrote:
>>
>> On Jun 26, 2008, at 2:43 PM, Joey Mukherjee wrote:
>>
>>> Suppose this type of setup was within a function, is it possible  
>>> to make OneDView the return value of this function?  In other  
>>> words, I would like to:
>>>
>>> array_type::const_array_view <1>::type OneDView;
>>> OneDView = multi_array[myindices];
>>> return OneDView;
>>>
>>
>> Off-hand, I see no reason why you couldn't do this.  So long as the  
>> multi_array is still in existence, you can build and keep a view of  
>> it.  How are you calling your function?  I'm afraid I can't tell  
>> what the problem might be since I can't see how it's really used.
>
> What would be the return value of the function?  In other words,  
> what would the function prototype be?  As in the code above, I am  
> not allowed to assign to a OneDView.  How can I write it so that I  
> am able to?
>
Rather than assign to a OneDView, you can construct a OneDView as the  
result of a function call:
typedef boost::multi_array<int,2> array_t;
array_t::const_array_view<1>::type
get_view (array_t& A) {
   return A[boost::indices[0][array_t::index_range()]];
}
int main() {
   array_t A(boost::extents[2][2]);
   array_t::const_array_view<1>::type
     V = get_view(A);
}
Perhaps I don't understand what you're trying to do.
> The way I have my function, I am calling it like so:
>
> double GetRealData (const SensorInfo &si, const std::vector <double>  
> &vals, const unsigned int whichPosition)
>
> The vals is a n-dimensional array of doubles and the si variable has  
> the desired slice and the sizes of my array.  Rather than return a  
> double, I would like to return a one-dimensional const_array_view.
>
If you don't know at compile-time how many dimensions your array is,  
then I think that you will need to copy the view into a one- 
dimensional multi_array.
>
> Thanks for your help!
>
> Joey
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://listarchives.boost.org/mailman/listinfo.cgi/boost-users