?? iterator
字號:
return (!(_Right < _Left));
}
bool operator<=(_Mytype_t%_Right)
{ // test if *this <= _Right
return (!(_Right < *this));
}
property const_reference default[difference_type]
{ // get subscripted element
const_reference get(difference_type _Pos)
{ // get _Pos element
ConstUncheckedRandomAccessIterator _Where = *this + _Pos;
return (*_Where);
}
};
_STLCLR_FIELD_ACCESS:
// data members
_Cont_t^ _Mycont; // owning container
difference_type _Myoffset; // offset into container
private:
virtual int get_bias_virtual() sealed
= _Myiter_t::get_bias
{ // get offset from wrapped iterator
return (get_bias());
}
virtual System::Object^ get_node_virtual() sealed
= _Myiter_t::get_node
{ // get node from wrapped iterator
return (get_node());
}
virtual bool valid_virtual() sealed
= _Myiter_t::valid
{ // test if iterator valid
return (valid());
}
virtual System::Object^ container_virtual() sealed
= _Myiter_t::container
{ // return owning container
return (container());
}
virtual void next_virtual() sealed
= _Myiter_t::next
{ // increment
next();
}
virtual bool equal_to_virtual(
_STLCLR Generic::IInputIterator<_Value_t>^ _Right) sealed
= _Myiter_t::equal_to
{ // test if *this == _Right
return (equal_to(_Right));
}
virtual const_reference get_cref_virtual() sealed
= _Myiter_t::get_cref
{ // return const reference to designated element
return (get_cref());
}
virtual reference get_ref_virtual() sealed
= _Myiter_t::get_ref
{ // return reference to designated element
#pragma warning(push)
#pragma warning(disable: 4715)
throw gcnew System::InvalidOperationException();
#pragma warning(pop)
}
virtual void prev_virtual() sealed
= _Myiter_t::prev
{ // decrement
prev();
}
virtual difference_type move_virtual(difference_type _Offset) sealed
= _Myiter_t::move
{ // incremented by integer
return (move(_Offset));
}
virtual difference_type distance_virtual(
_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right) sealed
= _Myiter_t::distance
{ // return difference of two iterators
return (distance(_Right));
}
virtual bool less_than_virtual(
_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right) sealed
= _Myiter_t::less_than
{ // test if *this < _Right
return (less_than(_Right));
}
};
template<typename _Cont_t>
ConstUncheckedRandomAccessIterator<_Cont_t>
_Unchecked(ConstRandomAccessIterator<_Cont_t> _Iter)
{ // return unchecked version
typedef typename _Cont_t::value_type _Value_t;
return (ConstUncheckedRandomAccessIterator<_Cont_t>(
(_Cont_t^)_Iter.container(),
_Iter.get_bias()));
}
//
// TEMPLATE VALUE CLASS RandomAccessIterator
//
template<typename _Cont_t>
value class RandomAccessIterator
: public _STLCLR Generic::IRandomAccessIterator<
typename _Cont_t::value_type>
{ // iterator for mutable random-access container
public:
// types
typedef typename _Cont_t::value_type _Value_t;
typedef RandomAccessIterator<_Cont_t> _Mytype_t;
typedef _STLCLR Generic::IRandomAccessIterator<_Value_t> _Myiter_t;
typedef random_access_iterator_tag iterator_category;
typedef _Value_t value_type;
typedef int difference_type;
typedef value_type% pointer;
typedef value_type% reference;
typedef value_type% const_reference;
// constructors and special members
RandomAccessIterator(_Cont_t^ _Cont, int _Offset)
: _Mycont(_Cont), _Myoffset(_Offset)
{ // construct from container pointer and offset
}
typedef ConstRandomAccessIterator<_Cont_t> _Myciter_t;
operator _Myciter_t()
{ // convert to const iterator
return (_Myciter_t(_Mycont, _Myoffset));
}
// generic conversions
typedef _STLCLR Generic::ContainerRandomAccessIterator<_Value_t>
_Mygeniter_t;
RandomAccessIterator(_Mygeniter_t% _Right)
: _Mycont((_Cont_t^)_Right.container()),
_Myoffset(_Right.get_bias())
{ // construct by copying a generic iterator
}
operator _Mygeniter_t()
{ // convert to generic iterator
return (_Mygeniter_t(_Mycont, _Myoffset));
}
// member functions
virtual System::Object^ Clone()
{ // return a copy
return (gcnew RandomAccessIterator(_Mycont, _Myoffset));
}
int get_bias()
{ // get offset from wrapped iterator
return (_Myoffset);
}
System::Object^ get_node()
{ // get node from wrapped iterator
return (nullptr);
}
bool valid()
{ // test if iterator valid
return (container() != nullptr
&& _Mycont->valid_bias(_Myoffset));
}
System::Object^ container()
{ // return owning container
return (_Mycont);
}
void next()
{ // increment
if (!_Mycont->valid_bias(_Myoffset + 1))
throw gcnew System::InvalidOperationException();
++_Myoffset;
}
bool equal_to(_STLCLR Generic::IInputIterator<_Value_t>^ _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(_Mytype_t% _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());
}
const_reference get_cref()
{ // return const reference to designated element
return (_Mycont->at_bias(_Myoffset));
}
reference get_ref()
{ // return reference to designated element
return (_Mycont->at_bias(_Myoffset));
}
void prev()
{ // decrement
if (!_Mycont->valid_bias(_Myoffset - 1))
throw gcnew System::InvalidOperationException();
--_Myoffset;
}
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);
}
difference_type distance(
_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _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());
}
bool less_than(_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _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
static reference operator->(RandomAccessIterator% _Left)
{ // return pointer to class object
return (_Left.get_ref());
}
static reference operator*(RandomAccessIterator% _Left)
{ // return reference to designated element
return (_Left.get_ref());
}
#pragma warning(push)
#pragma warning(disable:4460)
static RandomAccessIterator operator++(
RandomAccessIterator% _Left)
{ // return incremented
_Left.next();
return (_Left);
}
#pragma warning(pop)
bool operator==(_STLCLR Generic::IInputIterator<_Value_t>^ _Right)
{ // test if *this == _Right
return (equal_to(_Right));
}
bool operator==(_Mytype_t% _Right)
{ // test if *this == _Right
return (equal_to(_Right));
}
bool operator!=(_STLCLR Generic::IInputIterator<_Value_t>^ _Right)
{ // test if *this != _Right
return (!(*this == _Right));
}
bool operator!=(_Mytype_t% _Right)
{ // test if *this != _Right
return (!(*this == _Right));
}
#pragma warning(push)
#pragma warning(disable:4460)
static RandomAccessIterator operator--(
RandomAccessIterator% _Left)
{ // return decremented
_Left.prev();
return (_Left);
}
#pragma warning(pop)
static RandomAccessIterator operator+(
RandomAccessIterator% _Left,
difference_type _Right)
{ // return incremented by integer
RandomAccessIterator _Iter = _Left;
_Iter.move(_Right);
return (_Iter);
}
static RandomAccessIterator operator+(
difference_type _Left,
RandomAccessIterator% _Right)
{ // return incremented by integer
RandomAccessIterator _Iter = _Right;
_Iter.move(_Left);
return (_Iter);
}
static RandomAccessIterator operator-(
RandomAccessIterator% _Left,
difference_type _Right)
{ // return decremented by integer
RandomAccessIterator _Iter = _Left;
_Iter.move(-_Right); // can overflow
return (_Iter);
}
difference_type operator-(
_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right)
{ // return difference of two iterators
return (distance(_Right));
}
bool operator<(_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right)
{ // test if *this < _Right
return (less_than(_Right));
}
bool operator<(_Mytype_t% _Right)
{ // test if *this < _Right
return (less_than(_Right));
}
bool operator>=(_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right)
{ // test if *this >= _Right
return (!(*this < _Right));
}
bool operator>=(_Mytype_t% _Right)
{ // test if *this >= _Right
return (!(*this < _Right));
}
static bool operator>(_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Left,
_Mytype_t% _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
bool operator>(_Mytype_t%_Right)
{ // test if *this > _Right
return (_Right < *this);
}
static bool operator<=(
_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _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
RandomAccessIterator _Where = *this + _Pos;
return (*_Where);
}
void set(difference_type _Pos, value_type _Val)
{ // set _Pos element
RandomAccessIterator _Where = *this + _Pos;
*_Where = _Val;
}
};
_STLCLR_FIELD_ACCESS:
// data members
_Cont_t^ _Mycont; // owning container
difference_type _Myoffset; // offset into container
private:
virtual int get_bias_virtual() sealed
= _Myiter_t::get_bias
{ // get offset from wrapped iterator
return (get_bias());
}
virtual System::Object^ get_node_virtual() sealed
= _Myiter_t::get_node
{ // get node from wrapped iterator
return (get_node());
}
virtual bool valid_virtual() sealed
= _Myiter_t::valid
{ // test if iterator valid
return (valid());
}
virtual System::Object^ container_virtual() sealed
= _Myiter_t::container
{ // return owning container
return (container());
}
virtual void next_virtual() sealed
= _Myiter_t::next
{ // increment
next();
}
virtual bool equal_to_virtual(
_STLCLR Generic::IInputIterator<_Value_t>^ _Right) sealed
= _Myiter_t::equal_to
{ // test if *this == _Right
return (equal_to(_Right));
}
virtual const_reference get_cref_virtual() sealed
= _Myiter_t::get_cref
{ // return const reference to designated element
return (get_cref());
}
virtual reference get_ref_virtual() sealed
= _Myiter_t::get_ref
{ // return reference to designated element
return (get_ref());
}
virtual void prev_virtual() sealed
= _Myiter_t::prev
{ // decrement
prev();
}
virtual difference_type move_virtual(difference_type _Offset) sealed
= _Myiter_t::move
{ // incremented by integer
return (move(_Offset));
}
virtual difference_type distance_virtual(
_STLCLR Generi
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -