[Dune-devel] [Dune-Commit] [Commit] dune-common - 2fff527: [Release][Array] Provide a function for creating an array filled with copies of a single element
Steffen Müthing
steffen.muething at iwr.uni-heidelberg.de
Mon Dec 16 18:04:25 CET 2013
Hi Oliver,
Am 16.12.2013 um 17:07 schrieb Oliver Sander:
> Hi Steffen,
> I suppose the line
>
>> + std::cout << "test" << std::endl;
>
> is not there to stay?
no, not really… thanks for noticing ^^
>
> Why do I need this method anyway, when I have std::fill?
Because std::fill() (or array.fill(val)) doesn't really help me at all when trying to fix the deprecation warnings in PDELab ;-)
Throughout PDELab, there are several places where a YaspGrid is initialized as a member variable in a constructor, and
in that case creating an array and filling it in a second step just doesn't work. Code like this:
MyObject(…)
: _grid(Dune::FieldVector<double,dim>(1.0),Dune::fill_array<int,dim>(n),std::bitset<dim>(false),0)
, ….
Unfortunately, the standard doesn't provide an array constructor that copies a given object to all array elements...
>
> Is it going to go away when we kill our own array implementation?
Well, we'll need it until the standard gets amended… ;-)
Steffen
>
> Cheers,
> Oliver
>
> Am 16.12.2013 17:04, schrieb Steffen Müthing:
>> New commit, appeared at Mon Dec 16 17:04:40 2013 +0100
>> as part of the following ref changes:
>>
>> branch refs/heads/master updated from 9f1a112 -> 2fff527
>>
>> Browsable version: http://cgit.dune-project.org/repositories/dune-common/commit/?id=2fff527599173a8da0ce38a7c9d7f38053f04122
>>
>> ======================================================================
>>
>> commit 2fff527599173a8da0ce38a7c9d7f38053f04122
>> Author: Steffen Müthing <muething at dune-project.org>
>> Date: Mon Dec 16 17:02:12 2013 +0100
>>
>> [Release][Array] Provide a function for creating an array filled with copies of a single element
>>
>> The new YaspGrid constructors require an array with the number of cells
>> in each direction. Unfortunately, there is no array constructor that
>> takes a single element and copies it to all array elements.
>>
>> This patch adds a simple function Dune::fill_array() to do just that.
>>
>> dune/common/array.hh | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>>
>>
>> diff --git a/dune/common/array.hh b/dune/common/array.hh
>> index cf2cf3a..5b550d3 100644
>> --- a/dune/common/array.hh
>> +++ b/dune/common/array.hh
>> @@ -253,6 +253,23 @@ namespace Dune
>> return result;
>> }
>>
>> + //! Create an array and fill it with copies of the provided value.
>> + /**
>> + * \note This method is Dune-specific and not part of any C++ standard.
>> + */
>> + template<typename T, std::size_t n>
>> + array<T,n> fill_array(const T& t)
>> + {
>> + array<T,n> r;
>> + r.fill(t);
>> + std::cout << "test" << std::endl;
>> +#if HAVE_RVALUE_REFERENCES
>> + return std::move(r);
>> +#else
>> + return r;
>> +#endif
>> + }
>> +
>> /** @} */
>>
>> } // end namespace Dune
>>
>> _______________________________________________
>> Dune-Commit mailing list
>> Dune-Commit at dune-project.org
>> http://lists.dune-project.org/mailman/listinfo/dune-commit
>>
>
>
> _______________________________________________
> Dune-devel mailing list
> Dune-devel at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20131216/50c77a25/attachment.sig>
More information about the Dune-devel
mailing list