Add const version of ft_vec_access
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 21 Jun 2024 09:48:16 +0000 (11:48 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 21 Jun 2024 09:48:16 +0000 (11:48 +0200)
ft_arr/ft_vec_access.c
inc/ft_arr.h

index 8606b25c61fb8b64a45afe42b38bb33beff401b2..c60cce969b46b0799c07f8374c95449c3df87ec0 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/09 17:14:49 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/12/11 20:00:39 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/06/21 11:43:36 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -21,3 +21,12 @@ void *ft_vec_access(t_vec *vec, size_t index)
                return (NULL);
        return ((char *)vec->vec + vec->el_size * index);
 }
+
+const void     *ft_vec_caccess(const t_vec *vec, size_t index)
+{
+       if (!vec)
+               return (NULL);
+       if (index >= vec->size)
+               return (NULL);
+       return ((const char *)vec->vec + vec->el_size * index);
+}
index 7347e1ae2e71256d9cb45ae7daac590178424f09..a5a0ca730d3319f01c531582d0cc05b0e4453ad0 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/09 13:58:15 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/06/20 13:37:03 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/06/21 11:43:34 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -63,6 +63,7 @@ t_arr_stat    ft_vec_erase_range(t_vec *vec, size_t count, size_t index,
 t_arr_stat     ft_vec_init(t_vec *vec, size_t el_size);
 void           ft_vec_free(t_vec *vec, void (*free_el)(void *));
 void           *ft_vec_access(t_vec *vec, size_t index);
+const void     *ft_vec_caccess(const t_vec *vec, size_t index);
 
 /* It is probably better to use        (type *)vec->vec + index for pointer
  * or                                                          ((type *)vec->vec)[index] for value