make vec_len() and vec_cap() take a const ptr
This commit is contained in:
parent
d2cd52b971
commit
368dde5c89
@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
#ifndef _GENERIC_VEC_ONCE
|
#ifndef _GENERIC_VEC_ONCE
|
||||||
#define _GENERIC_VEC_ONCE
|
#define _GENERIC_VEC_ONCE
|
||||||
size_t vec_len(void *v);
|
size_t vec_len(const void *v);
|
||||||
size_t vec_cap(void *v);
|
size_t vec_cap(const void *v);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef TYPE *NAME;
|
typedef TYPE *NAME;
|
||||||
@ -38,10 +38,8 @@ VARDECL(const char *, __val_fmt);
|
|||||||
FUNCDECL(NAME, )();
|
FUNCDECL(NAME, )();
|
||||||
FUNCDECL(void, _term)(NAME v);
|
FUNCDECL(void, _term)(NAME v);
|
||||||
FUNCDECL(void, _fmt_register)(const char *val_fmt);
|
FUNCDECL(void, _fmt_register)(const char *val_fmt);
|
||||||
static inline FUNCDEF(size_t, _len)(NAME v) { return vec_len((void*)v); }
|
static inline FUNCDEF(size_t, _len)(const NAME v) { return vec_len((const void*)v); }
|
||||||
static inline FUNCDEF(size_t, _cap)(NAME v) { return vec_cap((void*)v); }
|
static inline FUNCDEF(size_t, _cap)(const NAME v) { return vec_cap((const void*)v); }
|
||||||
FUNCDECL(size_t, _len)(NAME v);
|
|
||||||
FUNCDECL(size_t, _cap)(NAME v);
|
|
||||||
FUNCDECL(Error, _fit)(NAME *v, size_t new_minimum_cap);
|
FUNCDECL(Error, _fit)(NAME *v, size_t new_minimum_cap);
|
||||||
FUNCDECL(Error, _push)(NAME *v, TYPE val);
|
FUNCDECL(Error, _push)(NAME *v, TYPE val);
|
||||||
FUNCDECL(TYPE, _pop)(NAME v);
|
FUNCDECL(TYPE, _pop)(NAME v);
|
||||||
@ -60,11 +58,11 @@ typedef struct _VecHeader {
|
|||||||
size_t cap, len;
|
size_t cap, len;
|
||||||
} _VecHeader;
|
} _VecHeader;
|
||||||
|
|
||||||
size_t vec_len(void *v) {
|
size_t vec_len(const void *v) {
|
||||||
return v == NULL ? 0 : _VEC_HEADER(v)->len;
|
return v == NULL ? 0 : _VEC_HEADER(v)->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t vec_cap(void *v) {
|
size_t vec_cap(const void *v) {
|
||||||
return v == NULL ? 0 : _VEC_HEADER(v)->cap;
|
return v == NULL ? 0 : _VEC_HEADER(v)->cap;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user