Skip to content

Commit

Permalink
type argument to sort
Browse files Browse the repository at this point in the history
  • Loading branch information
uecker committed Jun 1, 2024
1 parent 825cd07 commit 596cb6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define vec_realloc(T, x, M) \
({ \
vec(T) **__Ta = (x); \
_Static_assert(same_type_p(T, vec_eltype(*__Ta))); \
(void)TYPE_CHECK(typeof(typeof(vec_eltype(*__Ta)[])*), \
&(*__Ta)->data); \
(*__Ta)->N = (M); \
Expand Down Expand Up @@ -110,10 +109,11 @@ extern void noplate_qsort(void* ptr, size_t N, size_t si, noplate_qsort_cmp_func
#endif
#endif

#define vec_sort(v2, cmp) \
#define vec_sort(T, v2, cmp) \
({ \
auto __T1 = (v2); \
typedef vec_eltype(__T1) __ET; \
_Static_assert(same_type_unq_p(T, __ET), ""); \
struct { int CLOSURE_TYPE(xcmp)(const __ET*, const __ET*); } \
__d = { (cmp) }; \
NESTED(int, __cmp, (const void* a, const void* b, void* _d)) \
Expand Down
4 changes: 2 additions & 2 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ int main()
return *a - *b;
};

vec_sort(v, cmp);
vec_sort(int, v, cmp);

NESTED(int, cmp2, (const string_ptr* a, const string_ptr* b))
{
return strcmp(string_cstr(*a), string_cstr(*b));
};

vec_sort(s, cmp2);
vec_sort(string_ptr, s, cmp2);

string* ss = NULL_CHECK(string_alloc());

Expand Down

0 comments on commit 596cb6e

Please sign in to comment.