📄 generics.h
字号:
static const_reference operator->(
ConstContainerBidirectionalIterator% _Left)
{ // return pointer to class object
return (_Left.get_cref());
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static const_reference operator*(
ConstContainerBidirectionalIterator% _Left)
{ // return const reference to designated element
return (_Left.get_cref());
}
ConstContainerBidirectionalIterator operator++()
{ // return incremented
next();
return (*this);
}
ConstContainerBidirectionalIterator operator++(int)
{ // return incremented
ConstContainerBidirectionalIterator _Iter = *this;
++*this;
return (_Iter);
}
bool operator==(Generic::IInputIterator<TValue>^ _Right)
{ // test if *this == _Right
return (equal_to(_Right));
}
bool operator==(_Mytype_t% _Right)
{ // test if *this == _Right
return (equal_to(_Right));
}
bool operator!=(Generic::IInputIterator<TValue>^ _Right)
{ // test if *this != _Right
return (!(*this == _Right));
}
bool operator!=(_Mytype_t% _Right)
{ // test if *this != _Right
return (!(*this == _Right));
}
ConstContainerBidirectionalIterator operator--()
{ // return decremented
prev();
return (*this);
}
ConstContainerBidirectionalIterator operator--(int)
{ // return decremented
ConstContainerBidirectionalIterator _Iter = *this;
--*this;
return (_Iter);
}
// ConstContainerBidirectionalIterator^ operator+(difference_type _Right);
// static ConstContainerBidirectionalIterator^ operator+(
// difference_type _Left, ConstContainerBidirectionalIterator _Right);
// ConstContainerBidirectionalIterator^ operator-(difference_type _Right);
// difference_type operator-(ConstContainerBidirectionalIterator^ _Right);
// bool operator<(ConstContainerBidirectionalIterator^ _Right);
// bool operator>=(ConstContainerBidirectionalIterator^ _Right);
// bool operator>(ConstContainerBidirectionalIterator^ _Right);
// bool operator<=(ConstContainerBidirectionalIterator^ _Right);
_STLCLR_FIELD_ACCESS:
// data members
_Mynode_it^ _Mynode; // node into list
};
//
// GENERIC REF CLASS ContainerRandomAccessIterator
//
generic<typename TValue>
public ref class ContainerRandomAccessIterator
: public Generic::IRandomAccessIterator<TValue>
{ // iterator for mutable random-access container
public:
// types
typedef ContainerRandomAccessIterator<TValue> _Mytype_t;
typedef Generic::IRandomAccessIterator<TValue> _Myiter_t;
typedef Generic::IRandomAccessContainer<TValue> TCont;
typedef TValue value_type;
typedef int difference_type;
typedef value_type% pointer;
typedef value_type% reference;
typedef value_type% const_reference;
// basics
ContainerRandomAccessIterator()
: _Mycont(nullptr), _Myoffset(0)
{ // construct default
}
ContainerRandomAccessIterator(ContainerRandomAccessIterator% _Right)
: _Mycont(_Right._Mycont), _Myoffset(_Right._Myoffset)
{ // construct by copying an iterator
}
ContainerRandomAccessIterator% operator=(
ContainerRandomAccessIterator% _Right)
{ // assign an iterator
_Mycont = _Right._Mycont;
_Myoffset = _Right._Myoffset;
return (*this);
}
operator _Myiter_t^()
{ // convert to interface
return (this);
}
// constructors
ContainerRandomAccessIterator(TCont^ _Cont, int _Offset)
: _Mycont(_Cont), _Myoffset(_Offset)
{ // construct from container pointer and offset
}
// member functions
virtual System::Object^ Clone()
{ // return a copy
return (gcnew ContainerRandomAccessIterator(_Mycont, _Myoffset));
}
virtual int get_bias()
{ // get offset from wrapped iterator
return (_Myoffset);
}
virtual System::Object^ get_node()
{ // get node from wrapped iterator
return (nullptr);
}
virtual bool valid()
{ // test if iterator valid
return (container() != nullptr
&& _Mycont->valid_bias(_Myoffset));
}
virtual System::Object^ container()
{ // return owning container
return (_Mycont);
}
virtual void next()
{ // increment
if (!_Mycont->valid_bias(_Myoffset + 1))
throw gcnew System::InvalidOperationException();
++_Myoffset;
}
virtual bool equal_to(Generic::IInputIterator<TValue>^ _Right)
{ // test if *this == _Right
if (container() == nullptr
|| container() != _Right->container())
throw gcnew System::ArgumentException();
return (get_bias() == _Right->get_bias()
&& get_node() == _Right->get_node());
}
bool equal_to(ContainerRandomAccessIterator% _Right)
{ // test if *this == _Right
if (container() == nullptr
|| container() != _Right._Mycont)
throw gcnew System::ArgumentException();
return (_Myoffset == _Right._Myoffset);
}
virtual const_reference get_cref()
{ // return const reference to designated element
return (_Mycont->at_bias(_Myoffset));
}
virtual reference get_ref()
{ // return reference to designated element
return (_Mycont->at_bias(_Myoffset));
}
virtual void prev()
{ // decrement
if (!_Mycont->valid_bias(_Myoffset - 1))
throw gcnew System::InvalidOperationException();
--_Myoffset;
}
virtual difference_type move(difference_type _Offset)
{ // incremented by integer
difference_type _Newoffset = _Myoffset + _Offset; // can overflow
if (!_Mycont->valid_bias(_Newoffset))
throw gcnew System::InvalidOperationException();
_Myoffset = _Newoffset;
return (_Myoffset);
}
virtual difference_type distance(
Generic::IRandomAccessIterator<TValue>^ _Right)
{ // return difference of two iterators
if (container() == nullptr
|| container() != _Right->container())
throw gcnew System::ArgumentException();
return (get_bias() - _Right->get_bias());
}
difference_type distance(
_Mytype_t% _Right)
{ // return difference of two iterators
if (container() == nullptr
|| container() != _Right.container())
throw gcnew System::ArgumentException();
return (get_bias() - _Right.get_bias());
}
virtual bool less_than(Generic::IRandomAccessIterator<TValue>^ _Right)
{ // test if *this < _Right
if (container() == nullptr
|| container() != _Right->container())
throw gcnew System::ArgumentException();
return (get_bias() < _Right->get_bias());
}
bool less_than(_Mytype_t% _Right)
{ // test if *this < _Right
if (container() == nullptr
|| container() != _Right.container())
throw gcnew System::ArgumentException();
return (get_bias() < _Right.get_bias());
}
// operators
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static reference operator->(ContainerRandomAccessIterator% _Left)
{ // return pointer to class object
return (_Left.get_ref());
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static reference operator*(ContainerRandomAccessIterator% _Left)
{ // return reference to designated element
return (_Left.get_ref());
}
ContainerRandomAccessIterator operator++()
{ // return incremented
next();
return (*this);
}
ContainerRandomAccessIterator operator++(int)
{ // return incremented
ContainerRandomAccessIterator _Iter = *this;
++*this;
return (_Iter);
}
bool operator==(Generic::IInputIterator<TValue>^ _Right)
{ // test if *this == _Right
return (equal_to(_Right));
}
bool operator==(_Mytype_t% _Right)
{ // test if *this == _Right
return (equal_to(_Right));
}
bool operator!=(Generic::IInputIterator<TValue>^ _Right)
{ // test if *this != _Right
return (!(*this == _Right));
}
bool operator!=(_Mytype_t% _Right)
{ // test if *this != _Right
return (!(*this == _Right));
}
ContainerRandomAccessIterator operator--()
{ // return decremented
prev();
return (*this);
}
ContainerRandomAccessIterator operator--(int)
{ // return decremented
ContainerRandomAccessIterator _Iter = *this;
--*this;
return (_Iter);
}
ContainerRandomAccessIterator operator+(difference_type _Right)
{ // return incremented by integer
ContainerRandomAccessIterator _Iter = *this;
_Iter.move(_Right);
return (_Iter);
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static ContainerRandomAccessIterator operator+(difference_type _Left,
ContainerRandomAccessIterator% _Right)
{ // return incremented by integer
ContainerRandomAccessIterator _Iter = _Right;
_Iter.move(_Left);
return (_Iter);
}
ContainerRandomAccessIterator operator-(difference_type _Right)
{ // return decremented by integer
ContainerRandomAccessIterator _Iter = *this;
_Iter.move(-_Right); // can overflow
return (_Iter);
}
difference_type operator-(
Generic::IRandomAccessIterator<TValue>^ _Right)
{ // return difference of two iterators
return (distance(_Right));
}
bool operator<(Generic::IRandomAccessIterator<TValue>^ _Right)
{ // test if *this < _Right
return (less_than(_Right));
}
bool operator<(_Mytype_t% _Right)
{ // test if *this < _Right
return (less_than(_Right));
}
bool operator>=(Generic::IRandomAccessIterator<TValue>^ _Right)
{ // test if *this >= _Right
return (!(*this < _Right));
}
bool operator>=(_Mytype_t% _Right)
{ // test if *this >= _Right
return (!(*this < _Right));
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static bool operator>(Generic::IRandomAccessIterator<TValue>^ _Left,
_Mytype_t% _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
bool operator>(_Mytype_t%_Right)
{ // test if *this > _Right
return (_Right < *this);
}
[System::Diagnostics::CodeAnalysis::SuppressMessage("Microsoft.Design", "CA1000")]
static bool operator<=(Generic::IRandomAccessIterator<TValue>^ _Left,
_Mytype_t% _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
bool operator<=(_Mytype_t%_Right)
{ // test if *this <= _Right
return (!(_Right < *this));
}
property value_type default[difference_type]
{ // get or set subscripted element
value_type get(difference_type _Pos)
{ // get _Pos element
ContainerRandomAccessIterator _Where = *this + _Pos;
return (*_Where);
}
void set(difference_type _Pos, value_type _Val)
{ // set _Pos element
ContainerRandomAccessIterator _Where = *this + _Pos;
*_Where = _Val;
}
};
_STLCLR_FIELD_ACCESS:
// data members
TCont^ _Mycont; // owning container
difference_type _Myoffset; // offset into container
};
//
// GENERIC REF CLASS ConstContainerRandomAccessIterator
//
generic<typename TValue>
public ref class ConstContainerRandomAccessIterator
: public Generic::IRandomAccessIterator<TValue>
{ // iterator for nonmutable random-access container
public:
// types
typedef ConstContainerRandomAccessIterator<TValue> _Mytype_t;
typedef Generic::IRandomAccessIterator<TValue> _Myiter_t;
typedef Generic::IRandomAccessContainer<TValue> TCont;
typedef TValue value_type;
typedef int difference_type;
typedef value_type% pointer;
typedef value_type% reference;
typedef value_type% const_reference;
// basics
ConstContainerRandomAccessIterator()
: _Mycont(nullptr), _Myoffset(0)
{ // construct default
}
ConstContainerRandomAccessIterator(
ConstContainerRandomAccessIterator% _Right)
: _Mycont(_Right._Mycont), _Myoffset(_Right._Myoffset)
{ // construct by copying an iterator
}
ConstContainerRandomAccessIterator% operator=(
ConstContainerRandomAccessIterator% _Right)
{ // assign an iterator
_Mycont = _Right._Mycont;
_Myoffset = _Right._Myoffset;
return (*this);
}
operator _Myiter_t^()
{ // convert to interface
return (this);
}
// constructors and special members
ConstContainerRandomAccessIterator(TCont^ _Cont, int _Offset)
: _Mycont(_Cont), _Myoffset(_Offset)
{ // construct from container pointer and offset
}
ConstContainerRandomAccessIterator(
Generic::ContainerRandomAccessIterator<TValue>% _Right)
: _Mycont((TCont^)_Right.container()),
_Myoffset(_Right.get_bias())
{ // construct from mutable iterator
}
ConstContainerRandomAccessIterator% operator=(
Generic::ContainerRandomAccessIterator<TValue>% _Right)
{ // assign from mutable iterator
_Mycont = (TCont^)_Right.container();
_Myoffset = _Right.get_bias();
return (*this);
}
// member functions
virtual System::Object^ Clone()
{ // return a copy
return (gcnew ConstContainerRandomAccessIterator(_Mycont, _Myoffset));
}
virtual int get_bias()
{ // get offset from wrapped iterator
return (_Myoffset);
}
virtual System::Object^ get_node()
{ // get node from wrapped iterator
return (nullptr);
}
virtual bool valid()
{ // test if iterator valid
return (container() != nullptr
&& _Mycont->valid_bias(_Myoffset));
}
virtual System::Object^ container()
{ // return owning container
return (_Mycont);
}
virtual void next()
{ // increment
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -