[cfe-commits] [PATCH] [libcxx] avoid hardcoding buffer lengths

Saleem Abdulrasool compnerd at compnerd.org
Wed Dec 26 16:11:05 PST 2012


Hi Bigcheese, chandlerc,

Introduce a new countof template "macro" to determine the count of elements in
a statically allocated array.  Use this to remove the various static hardcoded
values for array element counts (strftime_l takes number of characters to write,
not the size of the buffer, though they are equivalent with char).

Provide an overload which takes two pointers (iterators) and returns the count
of elements that would fit in the array bounded by the iterators.  Do this to
avoid having to add a pointless static assertion along the lines of:

    static_assert(is_same<decltype(__ib),
                          typename remove_reference<decltype(__ie)>::type>::value,
                  "iterator type mismatch");

to ensure that the iterator types match when performing the calculation using
sizeof on either of the iterators to determine the size of a single element:

    (__ie - __ib) / sizeof(*__ib)


http://llvm-reviews.chandlerc.com/D245

Files:
  src/locale.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D245.1.patch
Type: text/x-patch
Size: 10608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121226/9d537aa8/attachment.bin>


More information about the cfe-commits mailing list