1.Containers::Iterator_base

YP J·2022년 8월 31일
0

ft_container

목록 보기
1/8

typedef ,typedef typename 의 차이
https://lecor.tistory.com/76

typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
  • iterator_category는 iterator_traits<Iterator> 에 의존하는 (있는) iterator_category 를 쓰겠다~ 라는 의미

참고 한곳
https://cplusplus.com/
https://github.com/gcc-mirror/gcc/blob/54c1bf7801758caf2ff54917e79a8c239643061c/libstdc%2B%2B-v3/include/bits/stl_iterator.h

iterator_base.hpp

  • #include <cstddef>

<cstddef>와 <cstdlib>는 C++ 프로그램에서 종종 사용되는 C 호환 헤더 파일이다.

이것은 C헤더파일 <stddef.h>와 <stdlib.h>의 새로운 버전으로, 공통상수, 매크로, 타입, 함수들을 정의하고 있다.

<cstddef>의 정의

식별자 : 의미

  • NULL : '정의되지 않음‘이나 ’값이 없음‘을 의미하는 포인터 값 (근데 얘는 C++11 임)

  • size_t : 원소의 개수같이 음수가 될 수 없는 사이즈 단위

  • ptrdiff_t : 포인터의 차이를 위한 signed 타입

  • offsetof() : struct나 union에서 멤버의 오프셋


iterator:template parameters

    struct input_iterator_tag {};
    struct outout_iterator_tag {};
    struct forword_iterator_tag         : public input_iterator_tag {};
    struct bidirectional_iterator_tag   : public forword_iterator_tag {};
    struct random_access_iterator_tag   : public bidirectional_iterator_tag {};

구조체 들이 계층적 구조인 이유

  • 구조체 들이 계층적 구조인 이유
  • 즉 forword 는 input 을 상속하고 bidrection 은 forword를 상속 하는 이유


원형 과 인자들의 의미
첫번째 이미지에 있음 근데 다시 정리

  • @param Category : Category to which the iterator belongs to
  • @param T : Type of elements pointed by the iterator
  • @param Distance : Type to represent the difference between two iterators
  • @param Pointer : Type to represent a pointer to an element pointed by the iterator
  • @param Reference : Type to represent a reference to an element pointed by the iterator

  • 갑자기 iterator_traits가 등장하는 이유

/**
 * Traits class defining properties of iterators. (T * sepcializtion)
 **/
    template <typename T>
    struct iterator_traits<T *>
    {
        typedef ptrdiff_t                       difference_type;
        typedef T                               value_type;
        typedef T*                              pointer;
        typedef T&                              reference;
        typedef random_access_iterator_tag      iterator_category;
    };
/**
 * Traits class defining properties of iterators. (const T * sepcializtion)
 **/
    template <typename T>
    struct iterator_traits<const T *>
    {
        typedef ptrdiff_t                       difference_type;
        typedef T                               value_type;
        typedef const T*                              pointer;
        typedef const T&                              reference;
        typedef random_access_iterator_tag      iterator_category;
    };            
}

요건 algorithm.hpp 할때 다시 정리 .

distance

profile
be pro

0개의 댓글