📄 map
字号:
property mapped_type default[key_type]
{ // get or set subscripted element
mapped_type get(key_type _Key)
{ // get _Key element
_Pairnb _Ans = insert_node(
gcnew _Object_t(gcnew _Key1_t(_Key)));
return (_Ans.first->_Value->second);
}
void set(key_type _Key, mapped_type _Val)
{ // set _Key element
node_type^ _Node = insert_node(
gcnew _Object_t(gcnew _Key1_t(_Key))).first;
_Node->_Value->second = _Val;
}
};
// converters
static value_type make_value(key_type _Key, mapped_type _Mapped)
{ // make a value_type
return (gcnew _Object_t(gcnew _Key1_t(_Key), _Mapped));
}
// mutators
size_type erase(key_type _Keyval)
{ // erase element at _Where
return (_Mybase_t::erase(%_Keyval));
}
pair_iter_bool insert(cliext::pair<key_type, mapped_type> _Val)
{ // try to insert node with value _Val, return iterator
_Pairnb _Ans = insert_node(make_value(_Val.first, _Val.second));
return (pair_iter_bool(iterator(_Ans.first),
_Ans.second));
}
iterator insert(iterator _Where,
cliext::pair<key_type, mapped_type> _Val)
{ // insert a key value, with hint
return (_Mybase_t::insert(_Where,
make_value(_Val.first, _Val.second)));
}
// searches
iterator find(key_type _Keyval)
{ // find an element that matches _Keyval, return iterator
return (_Mybase_t::find(%_Keyval));
}
size_type count(key_type _Keyval)
{ // count all elements that match _Keyval
return (_Mybase_t::count(%_Keyval));
}
iterator lower_bound(key_type _Keyval)
{ // find leftmost node not less than _Keyval
return (_Mybase_t::lower_bound(%_Keyval));
}
iterator upper_bound(key_type _Keyval)
{ // find leftmost node not less than _Keyval
return (_Mybase_t::upper_bound(%_Keyval));
}
pair_iter_iter equal_range(key_type _Keyval)
{ // find range equivalent to _Keyval
return (_Mybase_t::equal_range(%_Keyval));
}
};
//
// TEMPLATE CLASS map_select: _Key1_t, _Mapped_t REF SPECIALIZATION
//
template<typename _Key1_t,
typename _Mapped_t>
ref class map_select<_Key1_t, _Mapped_t, true, true>
: public map_base<_Key1_t^, _Mapped_t^, true, true>
{ // ordered red-black tree of unique keys + values
public:
// types
typedef _Key1_t^ _Gkey_t;
typedef _Mapped_t^ _Gmapped_t;
typedef map_select<_Key1_t, _Mapped_t, true, true> _Mytype_t;
typedef map_base<_Gkey_t, _Gmapped_t, true, true>
_Mybase_t;
// typedef System::Collections::Generic::IEnumerable<_Value_t> _Myenum_it;
// typedef _STLCLR GenericPair<_Gkey_t, _Gmapped_t> _Object_t;
typedef _Key1_t key_type;
typedef _Mapped_t mapped_type;
// typedef typename _Traits_t::value_type value_type;
// typedef typename _Traits_t::key_compare key_compare;
// typedef typename _Traits_t::value_compare value_compare;
// typedef int size_type;
// typedef int difference_type;
// typedef _Value_t value_type;
// typedef value_type% reference;
// typedef value_type% const_reference;
// typedef _Mycont_it generic_container;
// typedef value_type generic_value;
// typedef _STLCLR GenericPair<iterator^, bool> pair_iter_bool;
// typedef _STLCLR GenericPair<iterator^, iterator^> pair_iter_iter;
// basics
map_select()
: _Mybase_t()
{ // construct empty map from defaults
}
map_select(map_select% _Right)
: _Mybase_t((_Mybase_t%)_Right)
{ // construct by copying a list
}
map_select% operator=(map_select% _Right)
{ // assign
_Mybase_t::operator=(_Right);
return (*this);
}
// constructors
explicit map_select(key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct empty map from comparator
}
template<typename _Iter_t>
map_select(_Iter_t _First, _Iter_t _Last)
: _Mybase_t()
{ // construct map from [_First, _Last), default comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
map_select(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct map from [_First, _Last), comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
// accessors
property mapped_type default[key_type]
{ // get or set subscripted element
mapped_type get(key_type _Key)
{ // get _Key element
_Pairnb _Ans = insert_node(
gcnew _Object_t(gcnew _Key1_t(_Key), gcnew _Mapped_t));
return (*_Ans.first->_Value->second);
}
void set(key_type _Key, mapped_type _Val)
{ // set _Key element
node_type^ _Node = insert_node(
gcnew _Object_t(gcnew _Key1_t(_Key), gcnew _Mapped_t)).first;
_Node->_Value->second = gcnew _Mapped_t(_Val);
}
};
// converters
static value_type make_value(key_type _Key, mapped_type _Mapped)
{ // make a value_type
return (gcnew _Object_t(gcnew _Key1_t(_Key),
gcnew _Mapped_t(_Mapped)));
}
// mutators
size_type erase(key_type _Keyval) new
{ // erase element at _Where
return (_Mybase_t::erase(%_Keyval));
}
pair_iter_bool insert(cliext::pair<key_type, mapped_type> _Val) new
{ // try to insert node with value _Val, return iterator
_Pairnb _Ans = insert_node(make_value(_Val.first, _Val.second));
return (pair_iter_bool(iterator(_Ans.first),
_Ans.second));
}
iterator insert(iterator _Where,
cliext::pair<key_type, mapped_type> _Val) new
{ // insert a key value, with hint
return (_Mybase_t::insert(_Where,
make_value(_Val.first, _Val.second)));
}
// searches
iterator find(key_type _Keyval)
{ // find an element that matches _Keyval, return iterator
return (_Mybase_t::find(%_Keyval));
}
size_type count(key_type _Keyval)
{ // count all elements that match _Keyval
return (_Mybase_t::count(%_Keyval));
}
iterator lower_bound(key_type _Keyval)
{ // find leftmost node not less than _Keyval
return (_Mybase_t::lower_bound(%_Keyval));
}
iterator upper_bound(key_type _Keyval)
{ // find leftmost node not less than _Keyval
return (_Mybase_t::upper_bound(%_Keyval));
}
pair_iter_iter equal_range(key_type _Keyval)
{ // find range equivalent to _Keyval
return (_Mybase_t::equal_range(%_Keyval));
}
};
} // namespace cliext::impl
//
// TEMPLATE CLASS map
//
template<typename _Key1_t,
typename _Mapped_t>
ref class map
: public impl::map_select<
_Key1_t,
_Mapped_t,
__is_ref_class(typename _Dehandle<_Key1_t>::type)
&& !is_handle<_Key1_t>::value,
__is_ref_class(typename _Dehandle<_Mapped_t>::type)
&& !is_handle<_Mapped_t>::value>
{ // ordered red-black tree of unique keys + values
public:
// types
typedef map<_Key1_t, _Mapped_t> _Mytype_t;
typedef impl::map_select<
_Key1_t,
_Mapped_t,
__is_ref_class(typename _Dehandle<_Key1_t>::type)
&& !is_handle<_Key1_t>::value,
__is_ref_class(typename _Dehandle<_Mapped_t>::type)
&& !is_handle<_Mapped_t>::value> _Mybase_t;
// typedef _Key1_t key_type;
// typedef _Mapped_t mapped_type;
// typedef typename _Traits_t::value_type value_type;
// typedef typename _Traits_t::key_compare key_compare;
// typedef typename _Traits_t::value_compare value_compare;
// typedef int size_type;
// typedef int difference_type;
// typedef _Value_t value_type;
// typedef value_type% reference;
// typedef value_type% const_reference;
// typedef _Mycont_it generic_container;
// typedef value_type generic_value;
// typedef _STLCLR GenericPair<iterator^, bool> pair_iter_bool;
// typedef _STLCLR GenericPair<iterator^, iterator^> pair_iter_iter;
// basics
map()
: _Mybase_t()
{ // construct default
}
map(map% _Right)
: _Mybase_t((_Mybase_t%)_Right)
{ // construct by copying a list
}
map(map^ _Right)
: _Mybase_t((_Mybase_t%)*_Right)
{ // construct by copying a list
}
map% operator=(map% _Right)
{ // assign
_Mybase_t::operator=(_Right);
return (*this);
}
map% operator=(map^ _Right)
{ // assign
_Mybase_t::operator=(*_Right);
return (*this);
}
// constructors
explicit map(key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct empty map from comparator
}
template<typename _Iter_t>
map(_Iter_t _First, _Iter_t _Last)
: _Mybase_t()
{ // construct map from [_First, _Last), default comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
map(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct map from [_First, _Last), comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
map(_Myenum_it^ _Right)
: _Mybase_t()
{ // construct map from enumeration, default comparator
for each (value_type _Val in _Right)
insert(_Val);
}
map(_Myenum_it^ _Right,
key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct map from enumeration, comparator
for each (value_type _Val in _Right)
insert(_Val);
}
// mutators
void swap(map% _Right)
{ // exchange contents with _Right
_Mybase_t::swap(_Right);
}
// interfaces
public:
virtual System::Object^ Clone() override
{ // clone the vector
return (gcnew _Mytype_t(*this));
}
};
//
// TEMPLATE FUNCTION swap
//
template<typename _Key_t,
typename _Mapped_t> inline
void swap(map<_Key_t, _Mapped_t>% _Left,
map<_Key_t, _Mapped_t>% _Right)
{ // swap two maps
_Left.swap(_Right);
}
namespace impl {
//
// TEMPLATE CLASS multimap_base0
//
template<typename _Key_t,
typename _Mapped_t,
bool _Is_ref_key,
bool _Is_ref_mapped>
ref class multimap_base0
: public tree<
map_traits<_Key_t, _Mapped_t, true,
_Is_ref_key, _Is_ref_mapped> >,
System::Collections::Generic::ICollection<
System::Collections::Generic
::KeyValuePair<_Key_t, _Mapped_t>>
{ // ordered red-black tree of unique keys + values
public:
// types
typedef multimap_base0<_Key_t, _Mapped_t, _Is_ref_key, _Is_ref_mapped>
_Mytype_t;
typedef tree<
map_traits<_Key_t, _Mapped_t, true,
_Is_ref_key, _Is_ref_mapped> > _Mybase_t;
typedef _STLCLR GenericPair<_Key_t, _Mapped_t> _Object_t;
typedef _Key_t key_type;
typedef _Mapped_t mapped_type;
typedef System::Collections::Generic::KeyValuePair<_Key_t, _Mapped_t>
_Mykvpair_t;
typedef cli::array<_Mykvpair_t> _Mykvarray_t;
// basics
multimap_base0()
: _Mybase_t()
{ // construct empty map from defaults
}
multimap_base0(multimap_base0% _Right)
: _Mybase_t((_Mybase_t%)_Right)
{ // construct by copying a list
}
multimap_base0% operator=(multimap_base0% _Right)
{ // assign
_Mybase_t::operator=(_Right);
return (*this);
}
// constructors
explicit multimap_base0(key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct empty map from comparator
}
template<typename _Iter_t>
multimap_base0(_Iter_t _First, _Iter_t _Last)
: _Mybase_t()
{ // construct map from [_First, _Last), default comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
multimap_base0(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct map from [_First, _Last), comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
// interfaces
private:
property size_type Count_kvpair
{ // element count
virtual size_type get() sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>
::Count::get
{ // get element count
return (size());
}
};
property bool IsReadOnly_kvpair
{ // test if read only
virtual bool get() sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -