<commit_before><commit_msg>Add an implementation of C pointer types.<commit_after>/*!
 * Implementation of C pointer types.
 *
 * @author <NAME>
 */

#ifndef NSTL_INTERNAL_POINTER_H
#define NSTL_INTERNAL_POINTER_H

#include <nstl/operator.h>

#include <stddef.h>


#define NSTL_POINTER(value_type, pointer)                                      \
NSTL_TYPE(                                                                     \
                                                                               \
(inherit (NSTL_ARITHMETIC_OPERATORS(pointer)))                                 \
(drop (mul))                                                                   \
(drop (imul))                                                                  \
(drop (div))                                                                   \
(drop (idiv))                                                                  \
(drop (mod))                                                                   \
(drop (imod))                                                                  \
(drop (prom))                                                                  \
(drop (inv))                                                                   \
(add (                                                                         \
static inline pointer nstl_add(pointer, ptrdiff_t)(pointer self, ptrdiff_t n)  \
{                                                                              \
    return self + n;                                                           \
}                                                                              \
))                                                                             \
(iadd (                                                                        \
static inline pointer nstl_iadd(pointer, ptrdiff_t)(pointer *self, ptrdiff_t n) \
{                                                                              \
    return (*self) += n;                                                       \
}                                                                              \
))                                                                             \
(sub (                                                                         \
static inline ptrdiff_t nstl_sub(pointer, pointer)(pointer x, pointer y)       \
{                                                                              \
    return x - y;                                                              \
}                                                                              \
                                                                               \
static inline pointer nstl_sub(pointer, ptrdiff_t)(pointer self, ptrdiff_t n)  \
{                                                                              \
    return self - n;                                                           \
}                                                                              \
))                                                                             \
(isub (                                                                        \
static inline pointer nstl_isub(pointer, ptrdiff_t)(pointer *self, ptrdiff_t n) \
{                                                                              \
    return (*self) -= n;                                                       \
}                                                                              \
))                                                                             \
                                                                               \
(inherit (NSTL_COMPARISON_OPERATORS(pointer)))                                 \
(inherit (NSTL_LOGICAL_OPERATORS(pointer)))                                    \
(inherit (NSTL_ALLOCATION_OPERATORS(pointer)))                                 \
                                                                               \
(deref (                                                                       \
static inline value_type nstl_deref(pointer)(pointer p)                        \
{                                                                              \
    return *p;                                                                 \
}                                                                              \
))                                                                             \
                                                                               \
)                                                                              \
/**/

/* [[[cog

import nstl
cog.outl(nstl.generate_attributes(
    'deref(pointer)',

    implement=True, token=True,
))

]]] */
#define NSTL_TOKEN_deref (d e r e f)
#define NSTL_INSTRUCTION_deref(s, self, implementation) \
    NSTL_INSTRUCTION_implement(s, self, deref, implementation)
#define nstl_deref(pointer) JOY_CAT3(nstl_mangled_deref, _, pointer)
/* [[[end]]] */

#endif /* !NSTL_INTERNAL_POINTER_H */
{'fraction_non_alphanumeric': 0.05938242280285035, 'fraction_numerical': 0.0001979414093428345, 'mean_word_length': 0.3881868131868132, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 116, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5085366', 'n_tokens_mistral': 755, 'n_tokens_neox': 740, 'n_words': 146}