Subject: Re: [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-18 17:32:33
#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
Resolution: | Keywords:
-----------------------------------+----------------------------------------
Comment(by niels_dekker):
David Abrahams and I just mailed about the issue and we agreed that it
would be preferable to have such a function as a non-member. Because
tr1::array doesn't have a c_array() member function and std::array
probably won't have one either. (See
[http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#930 LWG
issue 930, Access to std::array data as built-in array type]) Such a
boost::get_c_array(arg) function could be overloaded to support both
std::array and boost::array.
So it could be implemented as follows:
{{{
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
T(&get_c_array(boost::array<T,N>& arg))[N]
{
return arg.elems;
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const boost::array<T,N>& arg))[N]
{
return arg.elems;
}
// Overload for std::array, assuming that std::array will have
// explicit conversion functions as discussed at the WG21 meeting
// in Summit, March 2009.
template <typename T, std::size_t N>
T(&get_c_array(std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
}}}
When rvalue references are supported, get_c_array could be overloaded for
rvalue arrays as well.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2857#comment:2> 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