/** @license 2016 Neil Edelman, distributed under the terms of the [MIT License](https://opensource.org/licenses/MIT). @abstract Stand-alone header <../src/array.h>; examples <../test/test_array.c>. @subtitle Contiguous dynamic array ![Example of array.](../doc/array/array.png) array> is a dynamic array that stores contiguous type>. Resizing may be necessary when increasing the size of the array; this incurs amortised cost, and any pointers to this memory may become stale. @param[ARRAY_NAME, ARRAY_TYPE] `` that satisfies `C` naming conventions when mangled and a valid tag-type, type>, associated therewith; required. `` is private, whose names are prefixed in a manner to avoid collisions. @param[ARRAY_COMPARE, ARRAY_IS_EQUAL] Compare `` trait contained in . Requires `[]compare` to be declared as compare_fn> or `[]is_equal` to be declared as bipredicate_fn>, respectfully, (but not both.) @param[ARRAY_TO_STRING] To string `` trait contained in . Requires `[]to_string` be declared as to_string_fn>. @param[ARRAY_EXPECT_TRAIT, ARRAY_TRAIT] Named traits are obtained by including `array.h` multiple times with `ARRAY_EXPECT_TRAIT` and then subsequently including the name in `ARRAY_TRAIT`. @param[ARRAY_HEAD, ARRAY_BODY] These go together to allow exporting non-static data between compilation units by separating the header head from the code body. `ARRAY_HEAD` needs identical `ARRAY_NAME` and `ARRAY_TYPE`. @std C89 */ #if !defined(ARRAY_NAME) || !defined(ARRAY_TYPE) #error Name or tag type undefined. #endif #if defined(ARRAY_TRAIT) ^ defined(BOX_TYPE) #error ARRAY_TRAIT name must come after ARRAY_EXPECT_TRAIT. #endif #if defined(ARRAY_COMPARE) && defined(ARRAY_IS_EQUAL) #error Only one can be defined at a time. #endif #if defined(ARRAY_TEST) && (!defined(ARRAY_TRAIT) && !defined(ARRAY_TO_STRING) \ || defined(ARRAY_TRAIT) && !defined(ARRAY_HAS_TO_STRING)) #error Test requires to string. #endif #if defined ARRAY_HEAD && (defined ARRAY_BODY || defined ARRAY_TRAIT) #error Can not be simultaneously defined. #endif #ifndef ARRAY_H /* */ #if !defined(restrict) && (!defined(__STDC__) || !defined(__STDC_VERSION__) \ || __STDC_VERSION__ < 199901L) #define ARRAY_RESTRICT /* Undo this at the end. */ #define restrict /* Attribute only in C99+. */ #endif #ifndef ARRAY_TRAIT /* */ #ifndef ARRAY_BODY /* */ #ifndef ARRAY_HEAD /* */ static void PA_(unused_base_coda)(void); static void PA_(unused_base)(void) { PA_(iterator)(0); PA_(iterator_at)(0, 0); PA_(element)(0); PA_(next)(0); PA_(previous)(0); PA_(size)(0); PA_(at)(0, 0); PA_(tell_size)(0, 0); A_(array)(); A_(array_)(0); A_(array_insert)(0, 0, 0); A_(array_new)(0); A_(array_shrink)(0); A_(array_remove)(0, 0); A_(array_lazy_remove)(0, 0); A_(array_clear)(0); A_(array_peek)(0); A_(array_pop)(0); A_(array_append)(0, 0); A_(array_splice)(0, 0, 0, 0); PA_(unused_base_coda)(); } static void PA_(unused_base_coda)(void) { PA_(unused_base)(); } #endif /* body --> */ #endif /* base code --> */ #ifdef ARRAY_TRAIT /* <-- trait: Will be different on different includes. */ #define BOX_TRAIT_NAME ARRAY_TRAIT #define PAT_(n) PA_(ARRAY_CAT(ARRAY_TRAIT, n)) #define AT_(n) A_(ARRAY_CAT(ARRAY_TRAIT, n)) #else /* trait --> */ #ifdef ARRAY_TO_STRING /* */ #undef PAT_ #undef AT_ #if defined(ARRAY_TEST) && !defined(ARRAY_TRAIT) /* */ #if defined(ARRAY_COMPARE) || defined(ARRAY_IS_EQUAL) /* */ #include "compare.h" /** \include */ #ifdef ARRAY_TEST /* */ #undef CMP_ /* From . */ #undef CMPCALL_ #ifdef ARRAY_COMPARE #undef ARRAY_COMPARE #else #undef ARRAY_IS_EQUAL #endif #endif /* compare trait --> */ #ifdef ARRAY_EXPECT_TRAIT /* */ #ifdef ARRAY_TRAIT #undef ARRAY_TRAIT #undef BOX_TRAIT_NAME #endif #ifdef ARRAY_RESTRICT #undef ARRAY_RESTRICT #undef restrict #endif