[Dune] [#758] Default implementation of Dune::array is not a drop-in replacement for std::array (Attachment added)

Dune flyspray at dune-project.org
Mon Mar 15 19:12:40 CET 2010


THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below. 

User who did this - Bård Skaflestad (bska) 

Attached to Project - Dune
Summary - Default implementation of Dune::array is not a drop-in replacement for std::array
Task Type - Bug Report
Category - Dune Modules
Status - Unconfirmed
Assigned To - 
Operating System - Unspecified / All
Severity - Low
Priority - Normal
Reported Version - SVN (pre2.0)
Due in Version - Undecided
Due Date - Undecided
Details - Guys,

I'm very sorry to be bringing up Dune::array once more.  I know it's been extensively debated (e.g., in FS438) and you probably do not want to rehash the arguments.  Still, if I may, I'd like to point out that the current default implementation of Dune::array (i.e., in the !HAVE_ARRAY case) is not a drop-in replacement for std::array.

Specifically, the (draft) standard for C++0x states (in chapter 23.3.1, point 2) that std::array is an "aggregate" (8.5.1) that can be initialized with the syntax

    array<T,N> a = { initializer-list };

Moreover, an "aggregate" (8.5.1) is 

    ... an array or a class (Clause 9) with no user-provided constructors (12.1), no private or
    protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).

For exposition the standard uses the name 'elems' for the internal array representation in std::array.  The actual name, however, is undefined (and the GNU libstc++ implementation uses the name '_M_instance').  The default implementation of Dune::array includes a constructor as well as protected non-static data members (the 'a' array).  Consequently, the following statement

    Dune::array<int,3> a = { {1, 2, 3} };

fails to compile in the !HAVE_ARRAY case.

I have attached a test program (initialize-array.cpp) which demonstrates the problem.  Here, class 'A' is a stripped-down version of the default Dune::array class.  For the purpose of this particular test, Dune::array corresponds to the INCLUDE_CTOR && HIDE_DATA case.  The program builds (and runs) when compiled with GCC 4.1 (which does not provide <array>) and GCC 4.4 (which does provide <array>, at least in -std=c++0x mode).  For kicks, you may define HAVE_ARRAY (on implementations which provide <array>) to demonstrate the std::array behaviour.

Finally, I have attached a (trivial) patch (array.hh.diff) which turns Dune::array into drop-in replacement for std::array--at least from the point of view of initialization lists.  As Dune::array is a fundamental class, however, I hesitate to propose this for inclusion in Dune.  I have build- (and run-) tested the patch on slightly outdated versions of dune-common (-r5920), dune-grid (-r6404), and dune-istl (-r1181), but I have not tested any other modules.

I welcome any and all discussion on this topic.

Best regards,
Bård Skaflestad
SINTEF ICT, Applied Mathematics

One or more files have been attached.

More information can be found at the following URL:
http://www.dune-project.org/flyspray/index.php?do=details&task_id=758

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.




More information about the Dune mailing list