|
Message-ID: <87k0wmyvtt.fsf@oldenburg2.str.redhat.com> Date: Tue, 22 Sep 2020 12:01:02 +0200 From: Florian Weimer <fweimer@...hat.com> To: Jonathan Wakely <jwakely@...hat.com> Cc: Alejandro Colomar <colomar.6.4.3@...il.com>, Ville Voutilainen <ville.voutilainen@...il.com>, gcc@....gnu.org, libstdc++ <libstdc++@....gnu.org>, Libc-alpha <libc-alpha@...rceware.org>, LKML <linux-kernel@...r.kernel.org>, libc-coord@...ts.openwall.com Subject: Re: Expose 'array_length()' macro in <sys/param.h> * Jonathan Wakely: > I don't see much point in using std::size here. If you're going to > provide the alternative implementation for when std::size isn't > defined, why not just use it always? > > template<typename _Tp, std::size_t _Num> > #if __cplusplus >= 201103L > constexpr > #endif > inline std::size_t > __array_length(const _Tp(&)[_Num]) __THROW > { > return _Num; > } > > This only requires <cstddef>, not <iterator>. I agree that this is an advantage. But the version without constexpr is not sufficient because __array_length does not produce a constant expression. I've seen something like this used instead: template<typename _Tp, std::size_t _Num> char (&___array_length(const _Tp(&)[_Num]))[_Num]; #define __array_length(v) (sizeof(___array_length(v))) If the function type is too cute, a helper struct could be used instead. Thanks, Florian -- Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.