Skip to content

#758 Default implementation of Dune::array is not a drop-in replacement for std::array

Metadata

Property Value
Reported by Bård Skaflestad (bard.skaflestad@sintef.no)
Reported at Mar 15, 2010 18:12
Type Bug Report
Version Git (pre2.4) [autotools]
Operating System Unspecified / All
Last edited by Oliver Sander (oliver.sander@tu-dresden.de)
Last edited at Mar 15, 2010 20:47
Closed by Oliver Sander (oliver.sander@tu-dresden.de)
Closed at Mar 15, 2010 20:47
Closed in version Unknown
Resolution Fixed
Comment in dune-common 5933

Description

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 ) and GCC 4.4 (which does provide , at least in -std=c++0x mode). For kicks, you may define HAVE_ARRAY (on implementations which provide ) 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

Attachments