/*** * collection.h - Windows Runtime Collection/Iterator Wrappers * * Copyright (c) Microsoft Corporation. All rights reserved. ****/ #pragma once #ifndef _COLLECTION_H_ #define _COLLECTION_H_ #ifndef RC_INVOKED #ifndef __cplusplus_winrt #error collection.h requires the /ZW compiler option. #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define _COLLECTION_ATTRIBUTES [::Platform::Metadata::RuntimeClassName] [::Windows::Foundation::Metadata::Default] #define _COLLECTION_TRANSLATE \ } catch (const ::std::bad_alloc&) { \ throw ref new OutOfMemoryException; \ } catch (const ::std::exception&) { \ throw ref new FailureException; \ } #ifndef _COLLECTION_WUXI #define _COLLECTION_WUXI 1 #endif #ifdef _WIN64 #pragma pack(push, 16) #else #pragma pack(push, 8) #endif #pragma warning(push, 4) #pragma warning(disable: 4451) // Usage of ref class 'Meow' inside this context can lead to invalid marshaling of object across contexts namespace Platform { namespace Collections { namespace Details { namespace WFC = ::Windows::Foundation::Collections; #if _COLLECTION_WUXI namespace WUXI = ::Windows::UI::Xaml::Interop; #endif // _COLLECTION_WUXI typedef ::Windows::Foundation::EventRegistrationToken Token; inline void ValidateBounds(bool b) { if (!b) { throw ref new OutOfBoundsException; } } inline void ValidateCounter(const ::std::shared_ptr& ctr, unsigned int good_ctr) { if (*ctr != good_ctr) { throw ref new ChangedStateException; } } inline void ValidateSize(size_t n) { if (n > 0x7FFFFFFFUL) { throw ref new OutOfMemoryException; } } template struct AlwaysFalse : public ::std::false_type { }; template struct Wrap { typedef T type; }; template struct Wrap : public ::std::conditional<__is_winrt_agile(T), T^, Agile> { }; template inline const T& MakeWrap(const T& t) { return t; } template inline typename ::std::enable_if>::type MakeWrap(T^ const & t) { return Agile(t); } template inline const T& Unwrap(const T& t) { return t; } template inline T^ Unwrap(const Agile& a) { return a.Get(); } template struct VectorEnableIf : public ::std::enable_if< ::std::is_same::value || ::std::is_same::type, U>::value, void **> { }; template inline void Init(::std::shared_ptr& ctr, ::std::shared_ptr& sp) { try { ctr = ::std::make_shared(0); sp = ::std::make_shared(); _COLLECTION_TRANSLATE } template inline void Init(::std::shared_ptr& ctr, ::std::shared_ptr& sp, A&& a) { try { ctr = ::std::make_shared(0); sp = ::std::make_shared(::std::forward(a)); ValidateSize(sp->size()); _COLLECTION_TRANSLATE } template inline void Init(::std::shared_ptr& ctr, ::std::shared_ptr& sp, A&& a, B&& b) { try { ctr = ::std::make_shared(0); sp = ::std::make_shared(::std::forward(a), ::std::forward(b)); ValidateSize(sp->size()); _COLLECTION_TRANSLATE } template inline void Init(::std::shared_ptr& ctr, ::std::shared_ptr& sp, A&& a, B&& b, C&& c) { try { ctr = ::std::make_shared(0); sp = ::std::make_shared(::std::forward(a), ::std::forward(b), ::std::forward(c)); ValidateSize(sp->size()); _COLLECTION_TRANSLATE } template inline void InitMoveVector(::std::shared_ptr& ctr, ::std::shared_ptr& sp, A&& a) { Init(ctr, sp, a.begin(), a.end()); } template inline void InitMoveVector(::std::shared_ptr& ctr, ::std::shared_ptr& sp, X&& x) { Init(ctr, sp, ::std::move(x)); } template inline void EmplaceWrappedRange(M& m, InIt first, InIt last) { for ( ; first != last; ++first) { ::std::pair p(*first); m.emplace(MakeWrap(p.first), MakeWrap(p.second)); } } template inline void InitMoveMap(::std::shared_ptr& ctr, ::std::shared_ptr& sp, A&& a) { Init(ctr, sp, a.key_comp()); EmplaceWrappedRange(*sp, a.begin(), a.end()); } template inline void InitMoveMap(::std::shared_ptr& ctr, ::std::shared_ptr& sp, X&& x) { Init(ctr, sp, ::std::move(x)); } inline void IncrementCounter(::std::shared_ptr& ctr) { if (++*ctr == static_cast(-1)) { // Wraparound is imminent! Create a fresh counter. ctr = ::std::make_shared(0); } } ref class VectorChangedEventArgs sealed : public _COLLECTION_ATTRIBUTES WFC::IVectorChangedEventArgs { internal: VectorChangedEventArgs(WFC::CollectionChange change, unsigned int index) : m_change(change), m_index(index) { } public: virtual property WFC::CollectionChange CollectionChange { virtual WFC::CollectionChange get() { return m_change; } } virtual property unsigned int Index { virtual unsigned int get() { if (m_change == WFC::CollectionChange::Reset) { throw ref new FailureException; } return m_index; } } private: WFC::CollectionChange m_change; unsigned int m_index; }; template ref class MapChangedEventArgsReset sealed : public _COLLECTION_ATTRIBUTES WFC::IMapChangedEventArgs { public: virtual property WFC::CollectionChange CollectionChange { virtual WFC::CollectionChange get() { return WFC::CollectionChange::Reset; } } virtual property K Key { virtual K get() { throw ref new FailureException; } } }; template ref class MapChangedEventArgs sealed : public _COLLECTION_ATTRIBUTES WFC::IMapChangedEventArgs { internal: MapChangedEventArgs(WFC::CollectionChange change, K key) : m_change(change), m_key(key) { } public: virtual property WFC::CollectionChange CollectionChange { virtual WFC::CollectionChange get() { return m_change; } } virtual property K Key { virtual K get() { return Unwrap(m_key); } } private: WFC::CollectionChange m_change; typename Wrap::type m_key; }; template inline bool VectorIndexOf(const ::std::vector::type>& v, T value, unsigned int * index) { auto pred = [&](const typename Wrap::type& elem) { return E()(Unwrap(elem), value); }; *index = static_cast(::std::find_if(v.begin(), v.end(), pred) - v.begin()); return *index < v.size(); } #if _COLLECTION_WUXI template struct is_hat : public ::std::false_type { }; template struct is_hat : public ::std::true_type { }; template inline bool VectorBindableIndexOf(::std::false_type, const ::std::vector::type>& v, Object^ o, unsigned int * index) { IBox^ ib = dynamic_cast^>(o); if (ib) { return VectorIndexOf(v, ib->Value, index); } else { *index = static_cast(v.size()); return false; } } template inline bool VectorBindableIndexOf(::std::true_type, const ::std::vector::type>& v, Object^ o, unsigned int * index) { T t = dynamic_cast(o); if (!o || t) { return VectorIndexOf(v, t, index); } else { *index = static_cast(v.size()); return false; } } template inline bool VectorBindableIndexOf(const ::std::vector::type>& v, Object^ o, unsigned int * index) { return VectorBindableIndexOf(is_hat(), v, o, index); } #endif // _COLLECTION_WUXI template inline unsigned int VectorGetMany(const ::std::vector::type>& v, unsigned int startIndex, WriteOnlyArray^ dest) { unsigned int capacity = dest->Length; unsigned int actual = static_cast(v.size()) - startIndex; if (actual > capacity) { actual = capacity; } for (unsigned int i = 0; i < actual; ++i) { dest->set(i, Unwrap(v[startIndex + i])); } return actual; } template ref class IteratorForVectorView sealed : public _COLLECTION_ATTRIBUTES WFC::IIterator #if _COLLECTION_WUXI , public WUXI::IBindableIterator #endif // _COLLECTION_WUXI { private: typedef ::std::vector::type> WrappedVector; typedef WFC::IIterator WFC_Base; #if _COLLECTION_WUXI typedef WUXI::IBindableIterator WUXI_Base; #endif // _COLLECTION_WUXI internal: IteratorForVectorView(const ::std::shared_ptr& ctr, const ::std::shared_ptr& vec) : m_ctr(ctr), m_vec(vec), m_good_ctr(*ctr), m_index(0) { } public: virtual property T Current { virtual T get() = WFC_Base::Current::get { ValidateCounter(m_ctr, m_good_ctr); ValidateBounds(m_index < m_vec->size()); return Unwrap((*m_vec)[m_index]); } } virtual property bool HasCurrent { virtual bool get() { ValidateCounter(m_ctr, m_good_ctr); return m_index < m_vec->size(); } } virtual bool MoveNext() { ValidateCounter(m_ctr, m_good_ctr); ValidateBounds(m_index < m_vec->size()); ++m_index; return m_index < m_vec->size(); } virtual unsigned int GetMany(WriteOnlyArray^ dest) { ValidateCounter(m_ctr, m_good_ctr); unsigned int actual = VectorGetMany(*m_vec, m_index, dest); m_index += actual; return actual; } private: #if _COLLECTION_WUXI virtual Object^ BindableCurrent() = WUXI_Base::Current::get { return Current; } #endif // _COLLECTION_WUXI ::std::shared_ptr m_ctr; ::std::shared_ptr m_vec; unsigned int m_good_ctr; unsigned int m_index; }; } // namespace Details template , bool = __is_valid_winrt_type(T)> ref class Vector; template , bool = __is_valid_winrt_type(T)> ref class VectorView; template ref class VectorView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::VectorView requires T to be a valid Windows Runtime type."); }; template ref class VectorView sealed : public _COLLECTION_ATTRIBUTES Details::WFC::IVectorView #if _COLLECTION_WUXI , public Details::WUXI::IBindableVectorView #endif // _COLLECTION_WUXI { private: typedef ::std::vector::type> WrappedVector; typedef Details::WFC::IVectorView WFC_Base; #if _COLLECTION_WUXI typedef Details::WUXI::IBindableVectorView WUXI_Base; #endif // _COLLECTION_WUXI internal: VectorView() { Details::Init(m_ctr, m_vec); m_good_ctr = 0; } explicit VectorView(unsigned int size) { Details::Init(m_ctr, m_vec, size); m_good_ctr = 0; } VectorView(unsigned int size, T value) { Details::Init(m_ctr, m_vec, size, Details::MakeWrap(value)); m_good_ctr = 0; } template explicit VectorView(const ::std::vector& v, typename Details::VectorEnableIf::type = nullptr) { Details::Init(m_ctr, m_vec, v.begin(), v.end()); m_good_ctr = 0; } template explicit VectorView(::std::vector&& v, typename Details::VectorEnableIf::type = nullptr) { Details::InitMoveVector(m_ctr, m_vec, ::std::move(v)); m_good_ctr = 0; } VectorView(const T * ptr, unsigned int size) { Details::Init(m_ctr, m_vec, ptr, ptr + size); m_good_ctr = 0; } template explicit VectorView(const T (&arr)[N]) { Details::Init(m_ctr, m_vec, arr, arr + N); m_good_ctr = 0; } template explicit VectorView(const ::std::array& a) { Details::Init(m_ctr, m_vec, a.begin(), a.end()); m_good_ctr = 0; } explicit VectorView(const Array^ arr) { Details::Init(m_ctr, m_vec, arr->begin(), arr->end()); m_good_ctr = 0; } template VectorView(InIt first, InIt last) { // SFINAE is unnecessary here. Details::Init(m_ctr, m_vec, first, last); m_good_ctr = 0; } VectorView(::std::initializer_list il) { Details::Init(m_ctr, m_vec, il.begin(), il.end()); m_good_ctr = 0; } public: virtual Details::WFC::IIterator^ First() = WFC_Base::First { Details::ValidateCounter(m_ctr, m_good_ctr); return ref new Details::IteratorForVectorView(m_ctr, m_vec); } virtual T GetAt(unsigned int index) = WFC_Base::GetAt { Details::ValidateCounter(m_ctr, m_good_ctr); Details::ValidateBounds(index < m_vec->size()); return Details::Unwrap((*m_vec)[index]); } virtual property unsigned int Size { virtual unsigned int get() { Details::ValidateCounter(m_ctr, m_good_ctr); return static_cast(m_vec->size()); } } virtual bool IndexOf(T value, unsigned int * index) = WFC_Base::IndexOf { *index = 0; Details::ValidateCounter(m_ctr, m_good_ctr); return Details::VectorIndexOf(*m_vec, value, index); } virtual unsigned int GetMany(unsigned int startIndex, WriteOnlyArray^ dest) { Details::ValidateCounter(m_ctr, m_good_ctr); Details::ValidateBounds(startIndex <= m_vec->size()); return Details::VectorGetMany(*m_vec, startIndex, dest); } private: friend ref class Vector; VectorView(const ::std::shared_ptr& ctr, const ::std::shared_ptr& vec) : m_ctr(ctr), m_vec(vec), m_good_ctr(*ctr) { } #if _COLLECTION_WUXI virtual Details::WUXI::IBindableIterator^ BindableFirst() = WUXI_Base::First { return safe_cast(First()); } virtual Object^ BindableGetAt(unsigned int index) = WUXI_Base::GetAt { return GetAt(index); } virtual bool BindableIndexOf(Object^ value, unsigned int * index) = WUXI_Base::IndexOf { *index = 0; Details::ValidateCounter(m_ctr, m_good_ctr); return Details::VectorBindableIndexOf(*m_vec, value, index); } #endif // _COLLECTION_WUXI ::std::shared_ptr m_ctr; ::std::shared_ptr m_vec; unsigned int m_good_ctr; }; template ref class Vector { static_assert(Details::AlwaysFalse::value, "Platform::Collections::Vector requires T to be a valid Windows Runtime type."); }; template ref class Vector sealed : public _COLLECTION_ATTRIBUTES Details::WFC::IObservableVector #if _COLLECTION_WUXI , public Details::WUXI::IBindableObservableVector #endif // _COLLECTION_WUXI { private: typedef ::std::vector::type> WrappedVector; typedef Details::WFC::IObservableVector WFC_Base; typedef Details::WFC::VectorChangedEventHandler WFC_Handler; #if _COLLECTION_WUXI typedef Details::WUXI::IBindableObservableVector WUXI_Base; typedef Details::WUXI::BindableVectorChangedEventHandler WUXI_Handler; #endif // _COLLECTION_WUXI internal: Vector() { Details::Init(m_ctr, m_vec); m_observed = false; } explicit Vector(unsigned int size) { Details::Init(m_ctr, m_vec, size); m_observed = false; } Vector(unsigned int size, T value) { Details::Init(m_ctr, m_vec, size, Details::MakeWrap(value)); m_observed = false; } template explicit Vector(const ::std::vector& v, typename Details::VectorEnableIf::type = nullptr) { Details::Init(m_ctr, m_vec, v.begin(), v.end()); m_observed = false; } template explicit Vector(::std::vector&& v, typename Details::VectorEnableIf::type = nullptr) { Details::InitMoveVector(m_ctr, m_vec, ::std::move(v)); m_observed = false; } Vector(const T * ptr, unsigned int size) { Details::Init(m_ctr, m_vec, ptr, ptr + size); m_observed = false; } template explicit Vector(const T (&arr)[N]) { Details::Init(m_ctr, m_vec, arr, arr + N); m_observed = false; } template explicit Vector(const ::std::array& a) { Details::Init(m_ctr, m_vec, a.begin(), a.end()); m_observed = false; } explicit Vector(const Array^ arr) { Details::Init(m_ctr, m_vec, arr->begin(), arr->end()); m_observed = false; } template Vector(InIt first, InIt last) { // SFINAE is unnecessary here. Details::Init(m_ctr, m_vec, first, last); m_observed = false; } Vector(::std::initializer_list il) { Details::Init(m_ctr, m_vec, il.begin(), il.end()); m_observed = false; } public: virtual Details::WFC::IIterator^ First() = WFC_Base::First { return ref new Details::IteratorForVectorView(m_ctr, m_vec); } virtual T GetAt(unsigned int index) = WFC_Base::GetAt { Details::ValidateBounds(index < m_vec->size()); return Details::Unwrap((*m_vec)[index]); } virtual property unsigned int Size { virtual unsigned int get() { return static_cast(m_vec->size()); } } virtual bool IndexOf(T value, unsigned int * index) = WFC_Base::IndexOf { *index = 0; return Details::VectorIndexOf(*m_vec, value, index); } virtual unsigned int GetMany(unsigned int startIndex, WriteOnlyArray^ dest) { Details::ValidateBounds(startIndex <= m_vec->size()); return Details::VectorGetMany(*m_vec, startIndex, dest); } virtual Details::WFC::IVectorView^ GetView() = WFC_Base::GetView { return ref new VectorView(m_ctr, m_vec); } virtual void SetAt(unsigned int index, T item) = WFC_Base::SetAt { try { Details::IncrementCounter(m_ctr); Details::ValidateBounds(index < m_vec->size()); (*m_vec)[index] = item; NotifyChanged(index); _COLLECTION_TRANSLATE } virtual void InsertAt(unsigned int index, T item) = WFC_Base::InsertAt { try { Details::IncrementCounter(m_ctr); Details::ValidateBounds(index <= m_vec->size()); Details::ValidateSize(m_vec->size() + 1); Emplace(m_vec->begin() + index, item, ::std::is_same()); NotifyInserted(index); _COLLECTION_TRANSLATE } virtual void Append(T item) = WFC_Base::Append { try { Details::IncrementCounter(m_ctr); size_t n = m_vec->size(); Details::ValidateSize(n + 1); EmplaceBack(item, ::std::is_same()); NotifyInserted(static_cast(n)); _COLLECTION_TRANSLATE } virtual void RemoveAt(unsigned int index) { try { Details::IncrementCounter(m_ctr); Details::ValidateBounds(index < m_vec->size()); m_vec->erase(m_vec->begin() + index); NotifyRemoved(index); _COLLECTION_TRANSLATE } virtual void RemoveAtEnd() { try { Details::IncrementCounter(m_ctr); Details::ValidateBounds(!m_vec->empty()); m_vec->pop_back(); NotifyRemoved(static_cast(m_vec->size())); _COLLECTION_TRANSLATE } virtual void Clear() { try { Details::IncrementCounter(m_ctr); m_vec->clear(); NotifyReset(); _COLLECTION_TRANSLATE } virtual void ReplaceAll(const Array^ arr) { try { Details::IncrementCounter(m_ctr); Details::ValidateSize(arr->Length); m_vec->assign(arr->begin(), arr->end()); NotifyReset(); _COLLECTION_TRANSLATE } virtual event WFC_Handler^ VectorChanged { virtual Details::Token add(WFC_Handler^ e) = WFC_Base::VectorChanged::add { m_observed = true; return m_wfc_event += e; } virtual void remove(Details::Token t) = WFC_Base::VectorChanged::remove { m_wfc_event -= t; } }; private: template void Emplace(A&& a, B&& b, ::std::false_type) { m_vec->emplace(::std::forward(a), ::std::forward(b)); } template void Emplace(A&& a, B&& b, ::std::true_type) { m_vec->insert(::std::forward(a), ::std::forward(b)); } template void EmplaceBack(A&& a, ::std::false_type) { m_vec->emplace_back(::std::forward(a)); } template void EmplaceBack(A&& a, ::std::true_type) { m_vec->push_back(::std::forward(a)); } void Notify(Details::WFC::CollectionChange change, unsigned int index) { if (m_observed) { auto args = ref new Details::VectorChangedEventArgs(change, index); m_wfc_event(this, args); #if _COLLECTION_WUXI m_wuxi_event(this, args); #endif // _COLLECTION_WUXI } } void NotifyReset() { Notify(Details::WFC::CollectionChange::Reset, 0); } void NotifyInserted(unsigned int index) { Notify(Details::WFC::CollectionChange::ItemInserted, index); } void NotifyRemoved(unsigned int index) { Notify(Details::WFC::CollectionChange::ItemRemoved, index); } void NotifyChanged(unsigned int index) { Notify(Details::WFC::CollectionChange::ItemChanged, index); } #if _COLLECTION_WUXI virtual Details::WUXI::IBindableIterator^ BindableFirst() = WUXI_Base::First { return safe_cast(First()); } virtual Object^ BindableGetAt(unsigned int index) = WUXI_Base::GetAt { return GetAt(index); } virtual bool BindableIndexOf(Object^ value, unsigned int * index) = WUXI_Base::IndexOf { *index = 0; return Details::VectorBindableIndexOf(*m_vec, value, index); } virtual Details::WUXI::IBindableVectorView^ BindableGetView() = WUXI_Base::GetView { return safe_cast(GetView()); } virtual void BindableSetAt(unsigned int index, Object^ item) = WUXI_Base::SetAt { SetAt(index, safe_cast(item)); } virtual void BindableInsertAt(unsigned int index, Object^ item) = WUXI_Base::InsertAt { InsertAt(index, safe_cast(item)); } virtual void BindableAppend(Object^ item) = WUXI_Base::Append { Append(safe_cast(item)); } virtual Details::Token BindableEventAdd(WUXI_Handler^ e) = WUXI_Base::VectorChanged::add { m_observed = true; return m_wuxi_event += e; } virtual void BindableEventRemove(Details::Token t) = WUXI_Base::VectorChanged::remove { m_wuxi_event -= t; } #endif // _COLLECTION_WUXI ::std::shared_ptr m_ctr; ::std::shared_ptr m_vec; bool m_observed; event WFC_Handler^ m_wfc_event; #if _COLLECTION_WUXI event WUXI_Handler^ m_wuxi_event; #endif // _COLLECTION_WUXI }; namespace Details { template ref class KeyValuePair sealed : public _COLLECTION_ATTRIBUTES WFC::IKeyValuePair { internal: KeyValuePair(const typename Wrap::type& key, const typename Wrap::type& value) : m_key(key), m_value(value) { } public: virtual property K Key { virtual K get() { return Unwrap(m_key); } } virtual property V Value { virtual V get() { return Unwrap(m_value); } } private: typename Wrap::type m_key; typename Wrap::type m_value; }; template ::type, K>::value> class WrapFunc { public: typedef F type; }; template class WrapFunc { public: typedef WrapFunc type; WrapFunc(const F& func) : m_func(func) { } size_t operator()(const Agile& k) const { return m_func(k.Get()); } bool operator()(const Agile& l, const Agile& r) const { return m_func(l.Get(), r.Get()); } private: F m_func; }; template struct WrapMap { typedef ::std::map::type, typename Wrap::type, typename WrapFunc::type> type; }; template struct WrapUnorderedMap { typedef ::std::unordered_map::type, typename Wrap::type, typename WrapFunc::type, typename WrapFunc::type> type; }; template ref class IteratorForAnyMapView sealed : public _COLLECTION_ATTRIBUTES WFC::IIterator^> { internal: IteratorForAnyMapView(const ::std::shared_ptr& ctr, const ::std::shared_ptr& m) : m_ctr(ctr), m_map(m), m_good_ctr(*ctr), m_iter(m->begin()) { } public: virtual property WFC::IKeyValuePair^ Current { virtual WFC::IKeyValuePair^ get() { ValidateCounter(m_ctr, m_good_ctr); ValidateBounds(m_iter != m_map->end()); return ref new KeyValuePair(m_iter->first, m_iter->second); } } virtual property bool HasCurrent { virtual bool get() { ValidateCounter(m_ctr, m_good_ctr); return m_iter != m_map->end(); } } virtual bool MoveNext() { ValidateCounter(m_ctr, m_good_ctr); ValidateBounds(m_iter != m_map->end()); ++m_iter; return m_iter != m_map->end(); } virtual unsigned int GetMany(WriteOnlyArray^>^ dest) { ValidateCounter(m_ctr, m_good_ctr); unsigned int capacity = dest->Length; unsigned int actual = 0; while (capacity > 0 && m_iter != m_map->end()) { dest->set(actual, ref new KeyValuePair(m_iter->first, m_iter->second)); ++m_iter; --capacity; ++actual; } return actual; } private: ::std::shared_ptr m_ctr; ::std::shared_ptr m_map; unsigned int m_good_ctr; typename WrappedMap::const_iterator m_iter; }; } // namespace Details template , bool = __is_valid_winrt_type(K), bool = __is_valid_winrt_type(V)> ref class Map; template , bool = __is_valid_winrt_type(K), bool = __is_valid_winrt_type(V)> ref class MapView; template , typename P = ::std::equal_to, bool = __is_valid_winrt_type(K), bool = __is_valid_winrt_type(V)> ref class UnorderedMap; template , typename P = ::std::equal_to, bool = __is_valid_winrt_type(K), bool = __is_valid_winrt_type(V)> ref class UnorderedMapView; template ref class MapView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::MapView requires K and V to be valid Windows Runtime types."); }; template ref class MapView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::MapView requires K to be a valid Windows Runtime type."); }; template ref class MapView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::MapView requires V to be a valid Windows Runtime type."); }; template ref class MapView sealed : public _COLLECTION_ATTRIBUTES Details::WFC::IMapView { private: typedef typename Details::WrapMap::type WrappedMap; typedef Details::IteratorForAnyMapView MyIterator; friend ref class Map; internal: explicit MapView(const C& comp = C()) { Details::Init(m_ctr, m_map, comp); m_good_ctr = 0; } explicit MapView(const ::std::map& m) { Details::Init(m_ctr, m_map, m.key_comp()); Details::EmplaceWrappedRange(*m_map, m.begin(), m.end()); m_good_ctr = 0; } explicit MapView(::std::map&& m) { Details::InitMoveMap(m_ctr, m_map, ::std::move(m)); m_good_ctr = 0; } template MapView(InIt first, InIt last, const C& comp = C()) { Details::Init(m_ctr, m_map, comp); Details::EmplaceWrappedRange(*m_map, first, last); m_good_ctr = 0; } MapView(::std::initializer_list< ::std::pair> il, const C& comp = C()) { Details::Init(m_ctr, m_map, comp); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_good_ctr = 0; } public: virtual Details::WFC::IIterator^>^ First() { Details::ValidateCounter(m_ctr, m_good_ctr); return ref new MyIterator(m_ctr, m_map); } virtual V Lookup(K key) { Details::ValidateCounter(m_ctr, m_good_ctr); auto i = m_map->find(Details::MakeWrap(key)); Details::ValidateBounds(i != m_map->end()); return Details::Unwrap(i->second); } virtual property unsigned int Size { virtual unsigned int get() { Details::ValidateCounter(m_ctr, m_good_ctr); return static_cast(m_map->size()); } } virtual bool HasKey(K key) { Details::ValidateCounter(m_ctr, m_good_ctr); return m_map->find(Details::MakeWrap(key)) != m_map->end(); } virtual void Split(Details::WFC::IMapView^ * firstPartition, Details::WFC::IMapView^ * secondPartition) { *firstPartition = nullptr; *secondPartition = nullptr; Details::ValidateCounter(m_ctr, m_good_ctr); } private: MapView(const ::std::shared_ptr& ctr, const ::std::shared_ptr& m) : m_ctr(ctr), m_map(m), m_good_ctr(*ctr) { } ::std::shared_ptr m_ctr; ::std::shared_ptr m_map; unsigned int m_good_ctr; }; template ref class UnorderedMapView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::UnorderedMapView requires K and V to be valid Windows Runtime types."); }; template ref class UnorderedMapView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::UnorderedMapView requires K to be a valid Windows Runtime type."); }; template ref class UnorderedMapView { static_assert(Details::AlwaysFalse::value, "Platform::Collections::UnorderedMapView requires V to be a valid Windows Runtime type."); }; template ref class UnorderedMapView sealed : public _COLLECTION_ATTRIBUTES Details::WFC::IMapView { private: typedef typename Details::WrapUnorderedMap::type WrappedMap; typedef Details::IteratorForAnyMapView MyIterator; friend ref class UnorderedMap; internal: UnorderedMapView() { Details::Init(m_ctr, m_map); m_good_ctr = 0; } explicit UnorderedMapView(size_t n) { Details::Init(m_ctr, m_map, n, H(), P()); m_good_ctr = 0; } UnorderedMapView(size_t n, const H& h) { Details::Init(m_ctr, m_map, n, h, P()); m_good_ctr = 0; } UnorderedMapView(size_t n, const H& h, const P& p) { Details::Init(m_ctr, m_map, n, h, p); m_good_ctr = 0; } explicit UnorderedMapView(const ::std::unordered_map& m) { Details::Init(m_ctr, m_map, m.bucket_count(), m.hash_function(), m.key_eq()); Details::EmplaceWrappedRange(*m_map, m.begin(), m.end()); m_good_ctr = 0; } explicit UnorderedMapView(::std::unordered_map&& m) { Details::InitMoveMap(m_ctr, m_map, ::std::move(m)); m_good_ctr = 0; } template UnorderedMapView(InIt first, InIt last) { Details::Init(m_ctr, m_map); Details::EmplaceWrappedRange(*m_map, first, last); m_good_ctr = 0; } template UnorderedMapView(InIt first, InIt last, size_t n) { Details::Init(m_ctr, m_map, n, H(), P()); Details::EmplaceWrappedRange(*m_map, first, last); m_good_ctr = 0; } template UnorderedMapView(InIt first, InIt last, size_t n, const H& h) { Details::Init(m_ctr, m_map, n, h, P()); Details::EmplaceWrappedRange(*m_map, first, last); m_good_ctr = 0; } template UnorderedMapView(InIt first, InIt last, size_t n, const H& h, const P& p) { Details::Init(m_ctr, m_map, n, h, p); Details::EmplaceWrappedRange(*m_map, first, last); m_good_ctr = 0; } UnorderedMapView(::std::initializer_list< ::std::pair> il) { Details::Init(m_ctr, m_map); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_good_ctr = 0; } UnorderedMapView(::std::initializer_list< ::std::pair> il, size_t n) { Details::Init(m_ctr, m_map, n, H(), P()); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_good_ctr = 0; } UnorderedMapView(::std::initializer_list< ::std::pair> il, size_t n, const H& h) { Details::Init(m_ctr, m_map, n, h, P()); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_good_ctr = 0; } UnorderedMapView(::std::initializer_list< ::std::pair> il, size_t n, const H& h, const P& p) { Details::Init(m_ctr, m_map, n, h, p); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_good_ctr = 0; } public: virtual Details::WFC::IIterator^>^ First() { Details::ValidateCounter(m_ctr, m_good_ctr); return ref new MyIterator(m_ctr, m_map); } virtual V Lookup(K key) { Details::ValidateCounter(m_ctr, m_good_ctr); auto i = m_map->find(Details::MakeWrap(key)); Details::ValidateBounds(i != m_map->end()); return Details::Unwrap(i->second); } virtual property unsigned int Size { virtual unsigned int get() { Details::ValidateCounter(m_ctr, m_good_ctr); return static_cast(m_map->size()); } } virtual bool HasKey(K key) { Details::ValidateCounter(m_ctr, m_good_ctr); return m_map->find(Details::MakeWrap(key)) != m_map->end(); } virtual void Split(Details::WFC::IMapView^ * firstPartition, Details::WFC::IMapView^ * secondPartition) { *firstPartition = nullptr; *secondPartition = nullptr; Details::ValidateCounter(m_ctr, m_good_ctr); } private: UnorderedMapView(const ::std::shared_ptr& ctr, const ::std::shared_ptr& m) : m_ctr(ctr), m_map(m), m_good_ctr(*ctr) { } ::std::shared_ptr m_ctr; ::std::shared_ptr m_map; unsigned int m_good_ctr; }; template ref class Map { static_assert(Details::AlwaysFalse::value, "Platform::Collections::Map requires K and V to be valid Windows Runtime types."); }; template ref class Map { static_assert(Details::AlwaysFalse::value, "Platform::Collections::Map requires K to be a valid Windows Runtime type."); }; template ref class Map { static_assert(Details::AlwaysFalse::value, "Platform::Collections::Map requires V to be a valid Windows Runtime type."); }; template ref class Map sealed : public _COLLECTION_ATTRIBUTES Details::WFC::IObservableMap { private: typedef typename Details::WrapMap::type WrappedMap; typedef Details::IteratorForAnyMapView MyIterator; typedef MapView MyView; typedef Details::WFC::MapChangedEventHandler WFC_Handler; internal: explicit Map(const C& comp = C()) { Details::Init(m_ctr, m_map, comp); m_observed = false; } explicit Map(const ::std::map& m) { Details::Init(m_ctr, m_map, m.key_comp()); Details::EmplaceWrappedRange(*m_map, m.begin(), m.end()); m_observed = false; } explicit Map(::std::map&& m) { Details::InitMoveMap(m_ctr, m_map, ::std::move(m)); m_observed = false; } template Map(InIt first, InIt last, const C& comp = C()) { Details::Init(m_ctr, m_map, comp); Details::EmplaceWrappedRange(*m_map, first, last); m_observed = false; } Map(::std::initializer_list< ::std::pair> il, const C& comp = C()) { Details::Init(m_ctr, m_map, comp); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_observed = false; } public: virtual Details::WFC::IIterator^>^ First() { return ref new MyIterator(m_ctr, m_map); } virtual V Lookup(K key) { auto i = m_map->find(Details::MakeWrap(key)); Details::ValidateBounds(i != m_map->end()); return Details::Unwrap(i->second); } virtual property unsigned int Size { virtual unsigned int get() { return static_cast(m_map->size()); } } virtual bool HasKey(K key) { return m_map->find(Details::MakeWrap(key)) != m_map->end(); } virtual Details::WFC::IMapView^ GetView() { return ref new MyView(m_ctr, m_map); } virtual bool Insert(K key, V value) { try { Details::IncrementCounter(m_ctr); Details::ValidateSize(m_map->size() + 1); auto p = m_map->emplace(Details::MakeWrap(key), Details::MakeWrap(value)); if (p.second) { NotifyInserted(key); } else { p.first->second = value; NotifyChanged(key); } return !p.second; _COLLECTION_TRANSLATE } virtual void Remove(K key) { try { Details::IncrementCounter(m_ctr); Details::ValidateBounds(m_map->erase(Details::MakeWrap(key)) == 1); NotifyRemoved(key); _COLLECTION_TRANSLATE } virtual void Clear() { try { Details::IncrementCounter(m_ctr); m_map->clear(); NotifyReset(); _COLLECTION_TRANSLATE } virtual event WFC_Handler^ MapChanged { virtual Details::Token add(WFC_Handler^ e) { m_observed = true; return m_wfc_event += e; } virtual void remove(Details::Token t) { m_wfc_event -= t; } }; private: void NotifyReset() { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgsReset); } } void NotifyInserted(K key) { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgs(Details::WFC::CollectionChange::ItemInserted, key)); } } void NotifyRemoved(K key) { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgs(Details::WFC::CollectionChange::ItemRemoved, key)); } } void NotifyChanged(K key) { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgs(Details::WFC::CollectionChange::ItemChanged, key)); } } ::std::shared_ptr m_ctr; ::std::shared_ptr m_map; bool m_observed; event WFC_Handler^ m_wfc_event; }; template ref class UnorderedMap { static_assert(Details::AlwaysFalse::value, "Platform::Collections::UnorderedMap requires K and V to be valid Windows Runtime types."); }; template ref class UnorderedMap { static_assert(Details::AlwaysFalse::value, "Platform::Collections::UnorderedMap requires K to be a valid Windows Runtime type."); }; template ref class UnorderedMap { static_assert(Details::AlwaysFalse::value, "Platform::Collections::UnorderedMap requires V to be a valid Windows Runtime type."); }; template ref class UnorderedMap sealed : public _COLLECTION_ATTRIBUTES Details::WFC::IObservableMap { private: typedef typename Details::WrapUnorderedMap::type WrappedMap; typedef Details::IteratorForAnyMapView MyIterator; typedef UnorderedMapView MyView; typedef Details::WFC::MapChangedEventHandler WFC_Handler; internal: UnorderedMap() { Details::Init(m_ctr, m_map); m_observed = false; } explicit UnorderedMap(size_t n) { Details::Init(m_ctr, m_map, n, H(), P()); m_observed = false; } UnorderedMap(size_t n, const H& h) { Details::Init(m_ctr, m_map, n, h, P()); m_observed = false; } UnorderedMap(size_t n, const H& h, const P& p) { Details::Init(m_ctr, m_map, n, h, p); m_observed = false; } explicit UnorderedMap(const ::std::unordered_map& m) { Details::Init(m_ctr, m_map, m.bucket_count(), m.hash_function(), m.key_eq()); Details::EmplaceWrappedRange(*m_map, m.begin(), m.end()); m_observed = false; } explicit UnorderedMap(::std::unordered_map&& m) { Details::InitMoveMap(m_ctr, m_map, ::std::move(m)); m_observed = false; } template UnorderedMap(InIt first, InIt last) { Details::Init(m_ctr, m_map); Details::EmplaceWrappedRange(*m_map, first, last); m_observed = false; } template UnorderedMap(InIt first, InIt last, size_t n) { Details::Init(m_ctr, m_map, n, H(), P()); Details::EmplaceWrappedRange(*m_map, first, last); m_observed = false; } template UnorderedMap(InIt first, InIt last, size_t n, const H& h) { Details::Init(m_ctr, m_map, n, h, P()); Details::EmplaceWrappedRange(*m_map, first, last); m_observed = false; } template UnorderedMap(InIt first, InIt last, size_t n, const H& h, const P& p) { Details::Init(m_ctr, m_map, n, h, p); Details::EmplaceWrappedRange(*m_map, first, last); m_observed = false; } UnorderedMap(::std::initializer_list< ::std::pair> il) { Details::Init(m_ctr, m_map); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_observed = false; } UnorderedMap(::std::initializer_list< ::std::pair> il, size_t n) { Details::Init(m_ctr, m_map, n, H(), P()); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_observed = false; } UnorderedMap(::std::initializer_list< ::std::pair> il, size_t n, const H& h) { Details::Init(m_ctr, m_map, n, h, P()); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_observed = false; } UnorderedMap(::std::initializer_list< ::std::pair> il, size_t n, const H& h, const P& p) { Details::Init(m_ctr, m_map, n, h, p); Details::EmplaceWrappedRange(*m_map, il.begin(), il.end()); m_observed = false; } public: virtual Details::WFC::IIterator^>^ First() { return ref new MyIterator(m_ctr, m_map); } virtual V Lookup(K key) { auto i = m_map->find(Details::MakeWrap(key)); Details::ValidateBounds(i != m_map->end()); return Details::Unwrap(i->second); } virtual property unsigned int Size { virtual unsigned int get() { return static_cast(m_map->size()); } } virtual bool HasKey(K key) { return m_map->find(Details::MakeWrap(key)) != m_map->end(); } virtual Details::WFC::IMapView^ GetView() { return ref new MyView(m_ctr, m_map); } virtual bool Insert(K key, V value) { try { Details::IncrementCounter(m_ctr); Details::ValidateSize(m_map->size() + 1); auto p = m_map->emplace(Details::MakeWrap(key), Details::MakeWrap(value)); if (p.second) { NotifyInserted(key); } else { p.first->second = value; NotifyChanged(key); } return !p.second; _COLLECTION_TRANSLATE } virtual void Remove(K key) { try { Details::IncrementCounter(m_ctr); Details::ValidateBounds(m_map->erase(Details::MakeWrap(key)) == 1); NotifyRemoved(key); _COLLECTION_TRANSLATE } virtual void Clear() { try { Details::IncrementCounter(m_ctr); m_map->clear(); NotifyReset(); _COLLECTION_TRANSLATE } virtual event WFC_Handler^ MapChanged { virtual Details::Token add(WFC_Handler^ e) { m_observed = true; return m_wfc_event += e; } virtual void remove(Details::Token t) { m_wfc_event -= t; } }; private: void NotifyReset() { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgsReset); } } void NotifyInserted(K key) { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgs(Details::WFC::CollectionChange::ItemInserted, key)); } } void NotifyRemoved(K key) { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgs(Details::WFC::CollectionChange::ItemRemoved, key)); } } void NotifyChanged(K key) { if (m_observed) { m_wfc_event(this, ref new Details::MapChangedEventArgs(Details::WFC::CollectionChange::ItemChanged, key)); } } ::std::shared_ptr m_ctr; ::std::shared_ptr m_map; bool m_observed; event WFC_Handler^ m_wfc_event; }; template class InputIterator; template class VectorIterator; template class VectorViewIterator; template class BackInsertIterator; } // namespace Collections } // namespace Platform template struct ::std::_Is_checked_helper< ::Platform::Collections::InputIterator> : public ::std::true_type { }; template struct ::std::_Is_checked_helper< ::Platform::Collections::VectorIterator> : public ::std::true_type { }; template struct ::std::_Is_checked_helper< ::Platform::Collections::VectorViewIterator> : public ::std::true_type { }; template struct ::std::_Is_checked_helper< ::Platform::Collections::BackInsertIterator> : public ::std::true_type { }; namespace Platform { namespace Collections { template class InputIterator { public: typedef ::std::input_iterator_tag iterator_category; typedef X value_type; typedef ptrdiff_t difference_type; typedef const X * pointer; typedef const X & reference; InputIterator() { } explicit InputIterator(Details::WFC::IIterator^ iter) { if (iter->HasCurrent) { m_iter = iter; m_val = iter->Current; } } bool operator==(const InputIterator& other) const { return !!m_iter == !!other.m_iter; } bool operator!=(const InputIterator& other) const { return !(*this == other); } reference operator*() const { return m_val; } pointer operator->() const { return &m_val; } InputIterator& operator++() { if (m_iter->MoveNext()) { m_val = m_iter->Current; } else { m_iter = nullptr; } return *this; } InputIterator operator++(int) { InputIterator old(*this); ++*this; return old; } private: Details::WFC::IIterator^ m_iter; X m_val; }; namespace Details { template class VectorProxy { public: VectorProxy(WFC::IVector^ v, ptrdiff_t n) : m_v(v), m_i(static_cast(n)) { } VectorProxy& operator=(const VectorProxy& other) { m_v->SetAt(m_i, other.m_v->GetAt(other.m_i)); return *this; } VectorProxy& operator=(T t) { m_v->SetAt(m_i, t); return *this; } operator T() const { return m_v->GetAt(m_i); } T operator->() const { return m_v->GetAt(m_i); } void swap(const VectorProxy& other) const { T t1(m_v->GetAt(m_i)); T t2(other.m_v->GetAt(other.m_i)); m_v->SetAt(m_i, t2); other.m_v->SetAt(other.m_i, t1); } void swap(T& t) const { T temp(t); t = m_v->GetAt(m_i); m_v->SetAt(m_i, temp); } private: WFC::IVector^ m_v; unsigned int m_i; }; template inline void swap(const VectorProxy& l, const VectorProxy& r) { l.swap(r); } template inline void swap(const VectorProxy& p, T& t) { p.swap(t); } template inline void swap(T& t, const VectorProxy& p) { p.swap(t); } template inline bool operator==(const VectorProxy& l, const VectorProxy& r) { return static_cast(l) == static_cast(r); } template inline bool operator==(const VectorProxy& l, const T& t) { return static_cast(l) == t; } template inline bool operator==(const T& t, const VectorProxy& r) { return t == static_cast(r); } template inline bool operator!=(const VectorProxy& l, const VectorProxy& r) { return static_cast(l) != static_cast(r); } template inline bool operator!=(const VectorProxy& l, const T& t) { return static_cast(l) != t; } template inline bool operator!=(const T& t, const VectorProxy& r) { return t != static_cast(r); } template inline bool operator<(const VectorProxy& l, const VectorProxy& r) { return static_cast(l) < static_cast(r); } template inline bool operator<(const VectorProxy& l, const T& t) { return static_cast(l) < t; } template inline bool operator<(const T& t, const VectorProxy& r) { return t < static_cast(r); } template inline bool operator<=(const VectorProxy& l, const VectorProxy& r) { return static_cast(l) <= static_cast(r); } template inline bool operator<=(const VectorProxy& l, const T& t) { return static_cast(l) <= t; } template inline bool operator<=(const T& t, const VectorProxy& r) { return t <= static_cast(r); } template inline bool operator>(const VectorProxy& l, const VectorProxy& r) { return static_cast(l) > static_cast(r); } template inline bool operator>(const VectorProxy& l, const T& t) { return static_cast(l) > t; } template inline bool operator>(const T& t, const VectorProxy& r) { return t > static_cast(r); } template inline bool operator>=(const VectorProxy& l, const VectorProxy& r) { return static_cast(l) >= static_cast(r); } template inline bool operator>=(const VectorProxy& l, const T& t) { return static_cast(l) >= t; } template inline bool operator>=(const T& t, const VectorProxy& r) { return t >= static_cast(r); } template class ArrowProxy { public: explicit ArrowProxy(T t) : m_val(t) { } const T * operator->() const { return &m_val; } private: T m_val; }; } // namespace Details template class VectorIterator { public: typedef ::std::random_access_iterator_tag iterator_category; typedef T value_type; typedef ptrdiff_t difference_type; typedef Details::VectorProxy * pointer; typedef Details::VectorProxy reference; VectorIterator() : m_v(nullptr), m_i(0) { } explicit VectorIterator(Details::WFC::IVector^ v) : m_v(v), m_i(0) { } reference operator*() const { return reference(m_v, m_i); } Details::ArrowProxy operator->() const { return Details::ArrowProxy(m_v->GetAt(static_cast(m_i))); } reference operator[](difference_type n) const { return reference(m_v, m_i + n); } VectorIterator& operator++() { ++m_i; return *this; } VectorIterator& operator--() { --m_i; return *this; } VectorIterator operator++(int) { VectorIterator old(*this); ++*this; return old; } VectorIterator operator--(int) { VectorIterator old(*this); --*this; return old; } VectorIterator& operator+=(difference_type n) { m_i += n; return *this; } VectorIterator& operator-=(difference_type n) { m_i -= n; return *this; } VectorIterator operator+(difference_type n) const { VectorIterator ret(*this); ret += n; return ret; } VectorIterator operator-(difference_type n) const { VectorIterator ret(*this); ret -= n; return ret; } difference_type operator-(const VectorIterator& other) const { return m_i - other.m_i; } bool operator==(const VectorIterator& other) const { return m_i == other.m_i; } bool operator!=(const VectorIterator& other) const { return m_i != other.m_i; } bool operator<(const VectorIterator& other) const { return m_i < other.m_i; } bool operator>(const VectorIterator& other) const { return m_i > other.m_i; } bool operator<=(const VectorIterator& other) const { return m_i <= other.m_i; } bool operator>=(const VectorIterator& other) const { return m_i >= other.m_i; } private: Details::WFC::IVector^ m_v; difference_type m_i; }; template inline VectorIterator operator+(ptrdiff_t n, const VectorIterator& i) { return i + n; } template class VectorViewIterator { public: typedef ::std::random_access_iterator_tag iterator_category; typedef T value_type; typedef ptrdiff_t difference_type; typedef T * pointer; typedef T reference; VectorViewIterator() : m_v(nullptr), m_i(0) { } explicit VectorViewIterator(Details::WFC::IVectorView^ v) : m_v(v), m_i(0) { } reference operator*() const { return m_v->GetAt(static_cast(m_i)); } Details::ArrowProxy operator->() const { return Details::ArrowProxy(m_v->GetAt(static_cast(m_i))); } reference operator[](difference_type n) const { return m_v->GetAt(static_cast(m_i + n)); } VectorViewIterator& operator++() { ++m_i; return *this; } VectorViewIterator& operator--() { --m_i; return *this; } VectorViewIterator operator++(int) { VectorViewIterator old(*this); ++*this; return old; } VectorViewIterator operator--(int) { VectorViewIterator old(*this); --*this; return old; } VectorViewIterator& operator+=(difference_type n) { m_i += n; return *this; } VectorViewIterator& operator-=(difference_type n) { m_i -= n; return *this; } VectorViewIterator operator+(difference_type n) const { VectorViewIterator ret(*this); ret += n; return ret; } VectorViewIterator operator-(difference_type n) const { VectorViewIterator ret(*this); ret -= n; return ret; } difference_type operator-(const VectorViewIterator& other) const { return m_i - other.m_i; } bool operator==(const VectorViewIterator& other) const { return m_i == other.m_i; } bool operator!=(const VectorViewIterator& other) const { return m_i != other.m_i; } bool operator<(const VectorViewIterator& other) const { return m_i < other.m_i; } bool operator>(const VectorViewIterator& other) const { return m_i > other.m_i; } bool operator<=(const VectorViewIterator& other) const { return m_i <= other.m_i; } bool operator>=(const VectorViewIterator& other) const { return m_i >= other.m_i; } private: Details::WFC::IVectorView^ m_v; difference_type m_i; }; template inline VectorViewIterator operator+(ptrdiff_t n, const VectorViewIterator& i) { return i + n; } template class BackInsertIterator : public ::std::iterator< ::std::output_iterator_tag, void, void, void, void> { public: explicit BackInsertIterator(Details::WFC::IVector^ v) : m_v(v) { } BackInsertIterator& operator=(const T& t) { m_v->Append(t); return *this; } BackInsertIterator& operator*() { return *this; } BackInsertIterator& operator++() { return *this; } BackInsertIterator operator++(int) { return *this; } private: Details::WFC::IVector^ m_v; }; namespace Details { template inline ::std::vector ToVector(I^ v) { unsigned int size = v->Size; ::std::vector ret(size); for (unsigned int actual = 0; actual < size; ) { Array^ arr = ref new Array(size - actual); unsigned int n = v->GetMany(actual, arr); if (n == 0) { throw ref new FailureException; } ::std::copy_n(arr->begin(), n, ret.begin() + actual); actual += n; } return ret; } } // namespace Details } // namespace Collections } // namespace Platform namespace Windows { namespace Foundation { namespace Collections { template inline ::Platform::Collections::InputIterator begin(IIterable^ i) { return ::Platform::Collections::InputIterator(i->First()); } template inline ::Platform::Collections::InputIterator end(IIterable^) { return ::Platform::Collections::InputIterator(); } template inline ::Platform::Collections::VectorIterator begin(IVector^ v) { return ::Platform::Collections::VectorIterator(v); } template inline ::Platform::Collections::VectorIterator end(IVector^ v) { return ::Platform::Collections::VectorIterator(v) + v->Size; } template inline ::Platform::Collections::VectorViewIterator begin(IVectorView^ v) { return ::Platform::Collections::VectorViewIterator(v); } template inline ::Platform::Collections::VectorViewIterator end(IVectorView^ v) { return ::Platform::Collections::VectorViewIterator(v) + v->Size; } template inline ::std::vector to_vector(IVector^ v) { return ::Platform::Collections::Details::ToVector(v); } template inline ::std::vector to_vector(IVectorView^ v) { return ::Platform::Collections::Details::ToVector(v); } template inline ::Platform::Collections::BackInsertIterator back_inserter(IVector^ v) { return ::Platform::Collections::BackInsertIterator(v); } template inline ::Platform::Collections::BackInsertIterator back_inserter(IObservableVector^ v) { return ::Platform::Collections::BackInsertIterator(v); } } // namespace Collections } // namespace Foundation } // namespace Windows namespace Platform { namespace Collections { template inline BackInsertIterator back_inserter(Vector^ v) { return BackInsertIterator(v); } } // namespace Collections } // namespace Platform template <> struct ::std::hash< ::Platform::String^> : public ::std::unary_function< ::Platform::String^, size_t> { size_t operator()(::Platform::String^ s) const { return ::std::_Hash_seq(reinterpret_cast(s->Data()), s->Length() * sizeof(wchar_t)); } }; #undef _COLLECTION_ATTRIBUTES #undef _COLLECTION_TRANSLATE #undef _COLLECTION_WUXI #pragma warning(pop) #pragma pack(pop) #endif // RC_INVOKED #endif // _COLLECTION_H_