[Boost-bugs] [Boost C++ Libraries] #2857: change return type of the c_array() member function

Subject: [Boost-bugs] [Boost C++ Libraries] #2857: change return type of the c_array() member function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-15 12:11:34


#2857: change return type of the c_array() member function
----------------------------------+-----------------------------------------
 Reporter: hervemart1_at_[hidden] | Owner: no-maintainer
     Type: Patches | Status: new
Milestone: Boost 1.39.0 | Component: array
  Version: Boost 1.38.0 | Severity: Cosmetic
 Keywords: |
----------------------------------+-----------------------------------------
 Currently the return type of c_array() member function is T* for
 boost::array<T,N>. Regarding its name we could expect from this function
 to return a reference on a C array rather than a pointer on the first
 element of the array.

 In returning T* type a piece of information about the C array is lost
 since the static size N is not transmitted.

 I suggest to change the existing c_array() member function:
 {{{
 T* c_array() { return elems; }

 }}}

 into,
 {{{
 T (&c_array())[N] { return elems; }
 }}}


 The both implementation are pretty similar since a reference on array is
 implicitly convertible into a pointer on the 1st element of this array.

 These following kind of lines of code would still work:
 {{{
 array<int,10> toto;
 int* item_ptr = toto.c_array();

 }}}

 but purist would now be able to write
 {{{
 int (&toto_ref)[10] = toto.c_array();

 }}}

 The improvement which would be brought by the change is that in our
 example sizeof( toto.c_array() ) would return value 10*sizeof(int), the
 real size of the C array.

 best regards, herve

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2857>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC