[C++]하부 구조

Philip Sung·2023년 4월 5일
0

[C++]

목록 보기
4/4
post-thumbnail

01 개요

본 문서에서는 C++에서 사용하는 표준 라이브러리 등의 구현을 위하여 자주 사용되는 C++의 하부구조수준의 라이브러리들에 관한 내용을 다룬다.

최종수정일 : 2023.04.05




02 allocator

작성 기준 C++ Version : C++98

02.01 구조

`
#include <memory>

template <class T> class allocator;
`

02.02 멤버변수

memberdefinitionrepresent
value_typeTElement type
pointerT*Pointer to element
referenceT&Reference to element
const_pointerconst T*Pointer to const element
const_referenceconst T&Reference to const element
size_typesize_tQuantities of elements
difference_typeptrdiff_tDifference between two pointers
rebind<Type>member classIts member type other is the equivalent allocator type to allocate elements of type Type

02.03 멤버함수

memberfunction
(constructor)Construct allocator object (public member function)
(destructor)Allocator destructor (public member function)
addressReturn address (public member function)
allocateAllocate block of storage (public member function)
deallocateRelease block of storage (public member function)
max_sizeMaximum size possible to allocate (public member function)
constructConstruct an object (public member function)
destroyDestroy an object (public member function)




03 traits

작성 기준 C++ Version : C++98

03.01 구조

`
#include <string>

template <class charT>
struct char_traits;
template <>
struct char_traits<char>;
template <>
struct char_traits<wchar_t>;

//Details
template<class charT> 
struct char_traits {

 typedef charT		char_type;
 typedef INT_T		int_type;
 typedef POS_T		pos_type;
 typedef OFF_T		off_type;
 typedef STATE_T	state_type;

 static char_type to_char_type(const int_type&); 
 static int_type to_int_type(const char_type&);
 static bool eq(const char_type&,const char_type&);
 static bool eq_int_type(const int_type&, const int_type&);
 static int_type eof();
 static int_type not_eof(const int_type&);
 static void assign(char_type&,const char_type&);
 static bool lt(const char_type&, const char_type&);
 static int compare(const char_type*, const char_type*,size_t);
 static size_t length(const char_type*);
 static const char_type* find(const char_type*,int n, const char_type&);
 static char_type* move(char_type*, const char_type*,size_t);
 static char_type* copy(char_type*,const char_type*, size_t);
 static char_type* assign(char_type*,size_t, const char_type&);
};
`

03.02 멤버변수

char_traits는 별도의 멤버 변수를 가지지 않고, 오직 추상화된 데이터형 정의를 갖는다.

03.03 멤버함수

Member functionDescription
assignAssigns one character value to another.
compareCompares up to a specified number of characters in two strings.
copyCopies a specified number of characters from one string to another.
_Copy_sCopies a specified number of characters from one string to another.
eofReturns the end-of-file (EOF) character.
eqTests whether two char_type characters are equal.
eq_int_typeTests whether two characters represented as int_types are equal.
findSearches for the first occurrence of a specified character in a range of characters.
lengthReturns the length of a string.
ltTests whether one character is less than another.
moveCopies a specified number of characters in a sequence to another, possible overlapping, sequence. Deprecated. Use char_traits::_Move_s instead.
_Move_sCopies a specified number of characters in a sequence to another, possible overlapping, sequence.
not_eofTests whether a character is the end-of-file (EOF) character.
to_char_typeConverts an int_type character to the corresponding char_type character and returns the result.
to_int_typeConverts a char_type character to the corresponding int_type character and returns the result.




04 iterator

04.01 구조

`
#include <iterator>
template <
	class Category,
	class T,
	class Distance = ptrdiff_t,
	class Pointer = T*,
	class Reference = T&
>
struct iterator {
   typedef T         value_type;
   typedef Distance  difference_type;
   typedef Pointer   pointer;
   typedef Reference reference;
   typedef Category  iterator_category;
};
`

04.02 멤버 변수

iterator는 별도의 멤버 변수를 가지지 않고, 오직 추상화된 데이터형 정의를 갖는다.

04.03 멤버 함수

Member functionDescription
advanceAdvances the iterator it by n element positions.
distanceCalculates the number of elements between first and last.
beginReturns an iterator pointing to the first element in the sequence
endReturns an iterator pointing to the past-the-end element in the sequence
prevReturns an iterator pointing to the element that it would be pointing to if advanced -n positions.
nextReturns an iterator pointing to the element that it would be pointing to if advanced n positions.
inserterConstructs an insert iterator that inserts new elements into x in successive locations starting at the position pointed by it.
front_inserterConstructs a front-insert iterator that inserts new elements at the beginning of x.
back_inserterConstructs a back-insert iterator that inserts new elements at the end of x.
make_move_iteratorA move_iterator is an iterator adaptor that adapts an iterator (it) so that dereferencing it produces rvalue references (as if std::move was applied), while all other operations behave the same.




05 ios_base

https://cplusplus.com/reference/ios/ios_base/?kw=ios_base
https://modoocode.com/144



profile
Philip Sung

0개의 댓글