|
|
|
|
| #ifndef _CLI_XUTILITY_
|
| #define _CLI_XUTILITY_
|
|
|
| #ifndef __cplusplus_cli
|
| #error STL/CLR can be used only in code compiled /clr, clr:pure, or /clr:safe
|
| #endif
|
|
|
| #if !defined _CRT_WINDOWS && !defined(UNDOCKED_WINDOWS_UCRT)
|
| #using <Microsoft.VisualC.STLCLR.dll>
|
| #endif
|
|
|
| #ifdef _M_CEE_SAFE
|
| #else
|
| #include <cstddef>
|
| #include <xutility>
|
| #endif
|
|
|
| #define _STLCLR_FIELD_ACCESS internal
|
| #define _STLCLR Microsoft::VisualC::StlClr::
|
|
|
| #define MAX_CONTAINER_SIZE ((int)((unsigned int)(-1) >> 1))
|
|
|
| namespace cliext {
|
|
|
|
|
|
|
|
|
|
|
|
|
| template<typename _Value_t>
|
| value class is_handle
|
| {
|
| public:
|
| static const bool value = false;
|
| };
|
|
|
| template<typename _Value_t>
|
| value class is_handle<_Value_t^>
|
| {
|
| public:
|
| static const bool value = true;
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Cont_t>
|
| value class _Container_traits
|
| {
|
| public:
|
| typedef typename _Cont_t::generic_container generic_container;
|
| typedef typename _Cont_t::generic_container^ generic_container_handle;
|
| };
|
|
|
| template<typename _Cont_t>
|
| value class _Container_traits<_Cont_t^>
|
| {
|
| public:
|
| typedef typename _Cont_t::generic_container generic_container;
|
| typedef typename _Cont_t::generic_container^ generic_container_handle;
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t>
|
| value class _Dehandle
|
| {
|
| public:
|
| typedef _Value_t type;
|
| };
|
|
|
| template<typename _Value_t>
|
| value class _Dehandle<_Value_t^>
|
| {
|
| public:
|
| typedef _Value_t type;
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| bool _Is_ref>
|
| ref class _Cont_make_value
|
| {
|
| public:
|
| static _Value_t make_value(_Value_t% _Val)
|
| {
|
| return (_Val);
|
| }
|
|
|
| static void unmake_value(_Value_t%)
|
| {
|
| }
|
| };
|
|
|
| template<typename _Value_t>
|
| ref class _Cont_make_value<_Value_t, true>
|
| {
|
| public:
|
| static _Value_t make_value(_Value_t% _Val)
|
| {
|
| return (gcnew typename _Dehandle<_Value_t>::type(_Val));
|
| }
|
|
|
| static void unmake_value(_Value_t% _Val)
|
| {
|
| delete _Val;
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| bool isref = !is_handle<_Value_t>::value && __is_ref_class(_Value_t)>
|
| value class _Generic_type;
|
|
|
| template<typename _Value_t>
|
| value class _Generic_type<_Value_t, false>
|
| {
|
| public:
|
| typedef _Value_t type;
|
| };
|
|
|
| template<typename _Value_t>
|
| value class _Generic_type<_Value_t, true>
|
| {
|
| public:
|
| typedef _Value_t^ type;
|
| };
|
|
|
|
|
|
|
|
|
| template<typename Mycont> inline
|
| Mycont^ _Handle_alloc(Mycont^)
|
| {
|
| return (gcnew Mycont);
|
| }
|
|
|
|
|
|
|
|
|
| #define _FIX_HANDLE(to, from, val) \
|
| cliext::_Fix_handle<to, from>::_Cvt(from(val))
|
|
|
| template<typename _To_t,
|
| typename _From_t>
|
| ref class _Fix_handle
|
| {
|
| public:
|
| static _To_t _Cvt(_From_t _Val)
|
| {
|
| return (_To_t(_Val));
|
| }
|
| };
|
|
|
| template<typename _To_t,
|
| typename _From_t>
|
| ref class _Fix_handle<_To_t^, _From_t>
|
| {
|
| public:
|
| static _To_t^ _Cvt(_From_t _Val)
|
| {
|
| return (gcnew _To_t(_Val));
|
| }
|
| };
|
|
|
| template<typename _To_t,
|
| typename _From_t>
|
| ref class _Fix_handle<_To_t, _From_t^>
|
| {
|
| public:
|
| static _To_t _Cvt(_From_t^ _Val)
|
| {
|
| return (*_Val);
|
| }
|
| };
|
|
|
| template<typename _To_t,
|
| typename _From_t>
|
| ref class _Fix_handle<_To_t^, _From_t^>
|
| {
|
| public:
|
| static _To_t^ _Cvt(_From_t^ _Val)
|
| {
|
| return (_Val);
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| ref class input_iterator_tag
|
| {
|
| public:
|
| typedef input_iterator_tag _Mytype_t;
|
|
|
| input_iterator_tag()
|
| {
|
| }
|
|
|
| input_iterator_tag(input_iterator_tag%)
|
| {
|
| }
|
| };
|
|
|
| ref class output_iterator_tag
|
| {
|
| public:
|
| typedef output_iterator_tag _Mytype_t;
|
|
|
| output_iterator_tag()
|
| {
|
| }
|
|
|
| output_iterator_tag(output_iterator_tag%)
|
| {
|
| }
|
| };
|
|
|
| ref class forward_iterator_tag
|
| : public input_iterator_tag
|
| {
|
| public:
|
| typedef forward_iterator_tag _Mytype_t;
|
|
|
| forward_iterator_tag()
|
| {
|
| }
|
|
|
| forward_iterator_tag(forward_iterator_tag%)
|
| {
|
| }
|
| };
|
|
|
| ref class bidirectional_iterator_tag
|
| : public forward_iterator_tag
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag _Mytype_t;
|
|
|
| bidirectional_iterator_tag()
|
| {
|
| }
|
|
|
| bidirectional_iterator_tag(bidirectional_iterator_tag%)
|
| {
|
| }
|
| };
|
|
|
| ref class random_access_iterator_tag
|
| : public bidirectional_iterator_tag
|
| {
|
| public:
|
| typedef random_access_iterator_tag _Mytype_t;
|
|
|
| random_access_iterator_tag()
|
| {
|
| }
|
|
|
| random_access_iterator_tag(random_access_iterator_tag%)
|
| {
|
| }
|
| };
|
|
|
| ref class _Int_iterator_tag
|
| {
|
| public:
|
| typedef _Int_iterator_tag _Mytype_t;
|
|
|
| _Int_iterator_tag()
|
| {
|
| }
|
|
|
| _Int_iterator_tag(_Int_iterator_tag%)
|
| {
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Cat>
|
| ref class _Map_iter_cat
|
| {
|
| public:
|
| typedef _Cat iterator_category;
|
| };
|
|
|
| #ifdef _M_CEE_SAFE
|
| #else
|
| template<>
|
| ref class _Map_iter_cat<std::input_iterator_tag>
|
| {
|
| public:
|
| typedef input_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| ref class _Map_iter_cat<std::output_iterator_tag>
|
| {
|
| public:
|
| typedef output_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| ref class _Map_iter_cat<std::forward_iterator_tag>
|
| {
|
| public:
|
| typedef forward_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| ref class _Map_iter_cat<std::bidirectional_iterator_tag>
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| ref class _Map_iter_cat<std::random_access_iterator_tag>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| };
|
| #endif
|
|
|
|
|
|
|
|
|
| template<class _Iter_t>
|
| value class iterator_traits
|
| {
|
| public:
|
| typedef typename _Map_iter_cat<
|
| typename _Iter_t::iterator_category>::iterator_category
|
| iterator_category;
|
| typedef typename _Iter_t::value_type value_type;
|
| typedef typename _Iter_t::difference_type difference_type;
|
| typedef difference_type distance_type;
|
| typedef typename _Iter_t::pointer pointer;
|
| typedef typename _Iter_t::reference reference;
|
| };
|
|
|
| template<typename _Iter_t>
|
| value class iterator_traits<_Iter_t^>
|
| {
|
| public:
|
| typedef typename _Iter_t::iterator_category iterator_category;
|
| typedef typename _Iter_t::value_type value_type;
|
| typedef typename _Iter_t::difference_type difference_type;
|
| typedef difference_type distance_type;
|
| typedef typename _Iter_t::pointer pointer;
|
| typedef typename _Iter_t::reference reference;
|
| };
|
|
|
| #ifdef _M_CEE_SAFE
|
| #else
|
| template<class _Ty>
|
| value class iterator_traits<_Ty *>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef std::ptrdiff_t difference_type;
|
| typedef std::ptrdiff_t distance_type;
|
| typedef _Ty *pointer;
|
| typedef _Ty& reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<const _Ty *>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef std::ptrdiff_t difference_type;
|
| typedef std::ptrdiff_t distance_type;
|
| typedef const _Ty *pointer;
|
| typedef const _Ty& reference;
|
| };
|
| #endif
|
|
|
|
|
|
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::IInputIterator<_Ty>>
|
| {
|
| public:
|
| typedef input_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::IOutputIterator<_Ty>>
|
| {
|
| public:
|
| typedef output_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::IForwardIterator<_Ty>>
|
| {
|
| public:
|
| typedef forward_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::IBidirectionalIterator<_Ty>>
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::IRandomAccessIterator<_Ty>>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ReverseBidirectionalIterator<_Ty>>
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ConstReverseBidirectionalIterator<_Ty>>
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ReverseRandomAccessIterator<_Ty>>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ConstReverseRandomAccessIterator<_Ty>>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ContainerBidirectionalIterator<_Ty>>
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ConstContainerBidirectionalIterator<_Ty>>
|
| {
|
| public:
|
| typedef bidirectional_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ContainerRandomAccessIterator<_Ty>>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<class _Ty>
|
| value class iterator_traits<
|
| _STLCLR Generic::ConstContainerRandomAccessIterator<_Ty>>
|
| {
|
| public:
|
| typedef random_access_iterator_tag iterator_category;
|
| typedef _Ty value_type;
|
| typedef int difference_type;
|
| typedef int distance_type;
|
| typedef typename _Ty% pointer;
|
| typedef typename _Ty% reference;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<bool>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<char>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<signed char>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<unsigned char>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<wchar_t>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<short>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<unsigned short>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<int>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<unsigned int>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<long>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<unsigned long>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<__int64>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
| template<>
|
| value class iterator_traits<unsigned __int64>
|
| {
|
| public:
|
| typedef _Int_iterator_tag iterator_category;
|
| };
|
|
|
|
|
|
|
|
|
| template<class _Iter_t> inline
|
| typename iterator_traits<_Iter_t>::iterator_category
|
| _Iter_category(_Iter_t)
|
| {
|
| typename iterator_traits<_Iter_t>::iterator_category _Cat;
|
|
|
| return (_Cat);
|
| }
|
|
|
|
|
|
|
|
|
| template<typename _InIt_t,
|
| typename _Diff_t> inline
|
| void _Iter_advance(_InIt_t% _Where, _Diff_t _Off,
|
| input_iterator_tag)
|
| {
|
| for (; 0 < _Off; --_Off)
|
| ++_Where;
|
| }
|
|
|
| template<typename _BidIt_t,
|
| typename _Diff_t> inline
|
| void _Iter_advance(_BidIt_t% _Where, _Diff_t _Off,
|
| bidirectional_iterator_tag)
|
| {
|
| for (; 0 < _Off; --_Off)
|
| ++_Where;
|
| for (; _Off < 0; ++_Off)
|
| --_Where;
|
| }
|
|
|
| template<typename _RanIt_t,
|
| typename _Diff_t> inline
|
| void _Iter_advance(_RanIt_t% _Where, _Diff_t _Off,
|
| random_access_iterator_tag)
|
| {
|
| _Where += _Off;
|
| }
|
|
|
| template<typename _InIt_t,
|
| typename _Diff_t> inline
|
| void advance(_InIt_t% _Where, _Diff_t _Off)
|
| {
|
| _Iter_advance(_Where, _Off, _Iter_category(_Where));
|
| }
|
|
|
|
|
|
|
|
|
| template<typename _InIt_t,
|
| typename _Diff_t> inline
|
| void _Iter_distance2(_InIt_t _First, _InIt_t _Last, _Diff_t% _Off,
|
| input_iterator_tag)
|
| {
|
| for (; _First != _Last; ++_First)
|
| ++_Off;
|
| }
|
|
|
| template<typename _RanIt_t,
|
| typename _Diff_t> inline
|
| void _Iter_distance2(_RanIt_t _First, _RanIt_t _Last, _Diff_t% _Off,
|
| random_access_iterator_tag)
|
| {
|
| _Off += (_Diff_t)(_Last - _First);
|
| }
|
|
|
| template<typename _InIt_t> inline
|
| int distance(_InIt_t _First, _InIt_t _Last)
|
| {
|
| int _Off = 0;
|
|
|
| _Iter_distance2(_First, _Last, _Off, _Iter_category(_First));
|
| return (_Off);
|
| }
|
|
|
| template<typename _InIt_t,
|
| typename _Diff_t> inline
|
| void _Iter_distance(_InIt_t _First, _InIt_t _Last, _Diff_t% _Off)
|
| {
|
| _Iter_distance2(_First, _Last, _Off, _Iter_category(_First));
|
| }
|
| }
|
| #endif
|
|
|