
From: mostafa_working_away@yahoo.com Date: Sun, 1 Dec 2013 20:10:53 -0800
Working with built-in array objects I find myself repeatedly needing to get the address of the first non-array element. This is so I can do generic array comparisons and copies without resorting to multiple loops. For example:
template
bool generic_array_equal(T (&lhs)[N], T const (&rhs)[N]) { return std::equal( address_of_first_nonarray_elem(lhs), address_of_first_nonarray_elem(lhs) + total_extent ::size, address_of_first_nonarray_elem(rhs)); } Any interest in adding such a function to the util library?
I needed code like this when developing a multiple-dimension extension to "array." What about (not tested; quasi-C++14):
//=====
template < typename T>
constexpr
auto inner_addressof( T &&t, false_type )
{ return addressof(forward<T>(t)); }
template < typename T, size_t N>
constexpr
auto inner_addressof( T (&t)[N], true_type )
{ return inner_addressof(t[0], integral_constant