1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Design Rationale</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../array.html" title="Chapter 5. Boost.Array"> 10<link rel="prev" href="../boost/array.html" title="Class template array"> 11<link rel="next" href="more/info.html" title="For more information..."> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="../boost/array.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../array.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="more/info.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="array.rationale"></a>Design Rationale</h2></div></div></div> 29<p>There was an important design tradeoff regarding the 30 constructors: We could implement array as an "aggregate" (see 31 Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would 32 mean: 33 </p> 34<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 35<p class="simpara">An array can be initialized with a 36 brace-enclosing, comma-separated list of initializers for the 37 elements of the container, written in increasing subscript 38 order:</p> 39<pre class="programlisting"><code class="computeroutput"><a class="link" href="../boost/array.html" title="Class template array">boost::array</a></code><int,4> a = { { 1, 2, 3 } };</pre> 40<p class="simpara">Note that if there are fewer elements in the 41 initializer list, then each remaining element gets 42 default-initialized (thus, it has a defined value).</p> 43</li></ul></div> 44<p>However, this approach has its drawbacks: <span class="bold"><strong> passing no initializer list means that the elements 45 have an indetermined initial value</strong></span>, because the rule says 46 that aggregates may have: 47 </p> 48<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 49<li class="listitem">No user-declared constructors.</li> 50<li class="listitem">No private or protected non-static data members.</li> 51<li class="listitem">No base classes.</li> 52<li class="listitem">No virtual functions.</li> 53</ul></div> 54<p> 55 </p> 56<p>Nevertheless, The current implementation uses this approach.</p> 57<p>Note that for standard conforming compilers it is possible to 58 use fewer braces (according to 8.5.1 (11) of the Standard). That is, 59 you can initialize an array as follows:</p> 60<pre class="programlisting"> 61<code class="computeroutput"><a class="link" href="../boost/array.html" title="Class template array">boost::array</a></code><int,4> a = { 1, 2, 3 }; 62</pre> 63<p>I'd appreciate any constructive feedback. <span class="bold"><strong>Please note: I don't have time to read all boost 64 mails. Thus, to make sure that feedback arrives to me, please send 65 me a copy of each mail regarding this class.</strong></span></p> 66<p>The code is provided "as is" without expressed or implied 67 warranty.</p> 68</div> 69<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 70<td align="left"></td> 71<td align="right"><div class="copyright-footer">Copyright © 2001-2004 Nicolai M. Josuttis<br>Copyright © 2012 Marshall Clow<p>Distributed under the Boost Software License, Version 1.0. 72 (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 73 <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 74 </p> 75</div></td> 76</tr></table> 77<hr> 78<div class="spirit-nav"> 79<a accesskey="p" href="../boost/array.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../array.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="more/info.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 80</div> 81</body> 82</html> 83