?? iterator
字號:
{ // 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);
// virtual difference_type distance_virtual(
// _STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right);
// virtual bool less_than_virtual(
// _STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right);
};
template<typename _Cont_t>
UncheckedBidirectionalIterator<_Cont_t>
_Unchecked(BidirectionalIterator<_Cont_t> _Iter)
{ // return unchecked version
UncheckedBidirectionalIterator<_Cont_t> _Newiter(
(typename _Cont_t::node_type^)_Iter.get_node());
return (_Newiter);
}
//
// TEMPLATE VALUE CLASS ReverseBidirectionalIterator
//
template<typename _Cont_t>
value class ReverseBidirectionalIterator
: public _STLCLR Generic::IBidirectionalIterator<
typename _Cont_t::value_type>
{ // iterator for mutable reverse bidirectional container
public:
// types
typedef typename _Cont_t::value_type _Value_t;
typedef ReverseBidirectionalIterator<_Cont_t> _Mytype_t;
typedef _STLCLR Generic::IBidirectionalIterator<
typename _Cont_t::value_type> _Myiter_t;
typedef typename _Cont_t::iterator _Mywrapped_t;
typedef bidirectional_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
ReverseBidirectionalIterator(_Mywrapped_t% _Iter)
: _Myiter(_Iter)
{ // construct from wrapped iterator
}
// member functions
virtual System::Object^ Clone()
{ // return a copy
return (gcnew ReverseBidirectionalIterator(_Myiter));
}
int get_bias()
{ // get offset from wrapped iterator
return (0);
}
System::Object^ get_node()
{ // get node from wrapped iterator
_Myiter.prev();
System::Object^ _Node = _Myiter.get_node();
_Myiter.next();
return (_Node);
}
bool valid()
{ // test if iterator valid
return (_Myiter.valid());
}
System::Object^ container()
{ // return owning container
return (_Myiter.container());
}
void next()
{ // increment
_Myiter.prev();
}
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
return (_Myiter.equal_to(_Right._Myiter));
}
const_reference get_cref()
{ // return const reference to designated element
_Myiter.prev();
const_reference _Ref = _Myiter.get_cref();
_Myiter.next();
return (_Ref);
}
reference get_ref()
{ // return reference to designated element
_Myiter.prev();
const_reference _Ref = _Myiter.get_ref();
_Myiter.next();
return (_Ref);
}
void prev()
{ // decrement
_Myiter.next();
}
// difference_type move(difference_type _Offset);
// difference_type distance(
// _STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right);
// bool less_than(_STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right);
// operators
static const_reference operator->(
ReverseBidirectionalIterator% _Left)
{ // return pointer to class object
return (_Left.get_ref());
}
static const_reference operator*(
ReverseBidirectionalIterator% _Left)
{ // return const reference to designated element
return (_Left.get_ref());
}
#pragma warning(push)
#pragma warning(disable:4460)
static ReverseBidirectionalIterator operator++(
ReverseBidirectionalIterator% _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 ReverseBidirectionalIterator operator--(
ReverseBidirectionalIterator% _Left)
{ // return decremented
_Left.prev();
return (_Left);
}
// static ReverseBidirectionalIterator operator+(
// ReverseBidirectionalIterator _Left,
// difference_type _Right);
// static ReverseBidirectionalIterator operator+(
// difference_type _Left,
// ReverseBidirectionalIterator _Right);
// static ReverseBidirectionalIterator operator-(
// difference_type _Right);
// difference_type operator-(ReverseBidirectionalIterator _Right);
// bool operator<(_STLCLR Generic::IReverseBidirectionalIterator^ _Right);
// bool operator>=(_STLCLR Generic::IReverseBidirectionalIterator^ _Right);
// bool operator>(_STLCLR Generic::IReverseBidirectionalIterator^ _Right);
// bool operator<=(_STLCLR Generic::IReverseBidirectionalIterator^ _Right);
// property const_reference default[difference_type];
_Mywrapped_t base()
{ // return wrapped iterator
return (_Myiter);
}
_STLCLR_FIELD_ACCESS:
// data members
_Mywrapped_t _Myiter; // the wrapped iterator
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);
// virtual difference_type distance_virtual(
// _STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right);
// virtual bool less_than_virtual(
// _STLCLR Generic::IRandomAccessIterator<_Value_t>^ _Right);
};
template<typename _Cont_t>
ReverseBidirectionalIterator<_Cont_t>
_Unchecked(ReverseBidirectionalIterator<_Cont_t> _Iter)
{ // return unchecked version
ReverseBidirectionalIterator<_Cont_t> _Newiter(_Iter.base());
return (_Newiter);
}
//
// TEMPLATE VALUE CLASS ConstRandomAccessIterator
//
template<typename _Cont_t>
value class ConstRandomAccessIterator
: public _STLCLR Generic::IRandomAccessIterator<
typename _Cont_t::value_type>
{ // iterator for nonmutable random-access container
public:
// types
typedef typename _Cont_t::value_type _Value_t;
typedef ConstRandomAccessIterator<_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
ConstRandomAccessIterator(_Cont_t^ _Cont, int _Offset)
: _Mycont(_Cont), _Myoffset(_Offset)
{ // construct from container pointer and offset
}
// generic conversions
typedef _STLCLR Generic::ConstContainerRandomAccessIterator<_Value_t>
_Mygeniter_t;
ConstRandomAccessIterator(_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 ConstRandomAccessIterator(_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
#pragma warning(push)
#pragma warning(disable: 4715)
throw gcnew System::InvalidOperationException();
#pragma warning(pop)
}
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 const_reference operator->(
ConstRandomAccessIterator% _Left)
{ // return pointer to class object
return (_Left.get_cref());
}
static const_reference operator*(
ConstRandomAccessIterator% _Left)
{ // return const reference to designated element
return (_Left.get_cref());
}
#pragma warning(push)
#pragma warning(disable:4460)
static ConstRandomAccessIterator operator++(
ConstRandomAccessIterator% _Left)
{ // return incremented
_Left.next();
return (_Left);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -