Re: fixed_array in storage.hpp

Joaquim Duran Comas <[email protected]>
Newsgroups gmane.comp.lib.boost.ublas
Message-ID <CAMnFju5T+FJpEKrGM4GB6S2P9AqxSerBy+C7LNqwG8GCmcH5tQ@mail.gmail.com>
Std::array hasn't any constructor defined in C++11, so the initialization
is done as:

std::array<int, 4> v = { { 1, 2, 3, 4} };

C++14 only defines the list constructor to std::array (as you've
wrote: fixed_vector<double,3>
v( {0, 1, 2} ) ;).



Respecting to the "lambda initialiation", I see it as a way to initialize
an array (or a vector, in general) following series like:

i^k: 0, 1, 4, 9, ....
k*i: 0, 2, 4, 6, 8,....
k: 5, 5, 5, 5,....
('k' is a constant value and 'i', the index of the elements of the array)

Joaquim Duran


2015-01-23 2:10 GMT+01:00 Nasos Iliopoulos <[email protected]>:

>  Thinking it over  there may be a reason to implement a fixed_array class
> and that is to remove the default (zero for numeric types) initialization
> of the std::array. This would speed up code like:
>
> (using ublas::fixed_vector here:)
>
> fixed_vector<double,3 > v; // Right now this will initialize to 3 zeros
> which is redundant.
>
> for ( auto i = 0 ; i != 3; i++)
> {
>    v[i] = i;
> }
>
> For small arrays though this there is a safe and much better alternative:
>
> fixed_vector<double,3> v( {0, 1, 2} ) ;
>
> and hence I am not sure if it would be wise to implement a
> non-initialization fixed_array class.
>
> Another option I was thinking was to implement some sort of "lambda
> initialization" i.e. a user provided function that is used in the
> constructor. The problem with this is that it may provide opportunities to
> break encapsulation and that would be terrible in the construction phase. I
> am not ruling out such a feature though.
>
> -Nasos
>
>  On 01/22/2015 05:59 PM, Joaquim Duran Comas wrote:
>
> I see. I can use std:array.
>
>
> 2015-01-22 15:03 GMT+01:00 Nasos Iliopoulos <[email protected]>:
>
>>  Why do you want to do that? Can't you use std::array?
>>
>> On 01/21/2015 08:04 PM, Joaquim Duran Comas wrote:
>>
>> I would like to create a fixed_array in strorage.hpp file. Is there any
>> inconvenient?
>>
>>  Joaquim Duran
>>
>>
>>
>>  _______________________________________________
>> ublas mailing [email protected]://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: [email protected]
>>
>>
>>
>> _______________________________________________
>> ublas mailing list
>> [email protected]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: [email protected]
>>
>
>
>
> _______________________________________________
> ublas mailing [email protected]://lists.boost.org/mailman/listinfo.cgi/ublas
>
> Sent to: [email protected]
>
>
>
> _______________________________________________
> ublas mailing list
> [email protected]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: [email protected]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.