зеркало из https://github.com/microsoft/cppwinrt.git
C++20 ranges support (#900)
This commit is contained in:
Родитель
122b732393
Коммит
8684e14771
|
@ -27,6 +27,7 @@ call msbuild /p:Configuration=%target_configuration%,Platform=%target_platform%,
|
|||
call msbuild /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% test\nuget\NugetTest.sln
|
||||
|
||||
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test
|
||||
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_cpp20
|
||||
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_win7
|
||||
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_fast
|
||||
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_slow
|
||||
|
|
22
cppwinrt.sln
22
cppwinrt.sln
|
@ -103,6 +103,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_win7", "test\test_win7
|
|||
{A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} = {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_cpp20", "test\test_cpp20\test_cpp20.vcxproj", "{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{D613FB39-5035-4043-91E2-BAB323908AF4} = {D613FB39-5035-4043-91E2-BAB323908AF4}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM = Debug|ARM
|
||||
|
@ -435,6 +440,22 @@ Global
|
|||
{2EF696B9-7F4A-410F-AE5C-5301565C0F08}.Release|x64.Build.0 = Release|x64
|
||||
{2EF696B9-7F4A-410F-AE5C-5301565C0F08}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2EF696B9-7F4A-410F-AE5C-5301565C0F08}.Release|x86.Build.0 = Release|Win32
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|x64.Build.0 = Debug|x64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Debug|x86.Build.0 = Debug|Win32
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|ARM.Build.0 = Release|ARM
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x64.ActiveCfg = Release|x64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x64.Build.0 = Release|x64
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x86.ActiveCfg = Release|Win32
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -457,6 +478,7 @@ Global
|
|||
{D48A96C2-8512-4CC3-B6E4-7CFF07ED8ED3} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
|
||||
{08C40663-B6A3-481E-8755-AE32BAD99501} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
|
||||
{2EF696B9-7F4A-410F-AE5C-5301565C0F08} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
|
||||
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {2783B8FD-EA3B-4D6B-9F81-662D289E02AA}
|
||||
|
|
|
@ -1283,13 +1283,18 @@ namespace cppwinrt
|
|||
static_cast<D&>(*this) = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
return static_cast<D&>(*this);
|
||||
}
|
||||
|
||||
auto operator*() const
|
||||
{
|
||||
return Current();
|
||||
}
|
||||
|
||||
void operator++(int)
|
||||
{
|
||||
++(*this);
|
||||
}
|
||||
)");
|
||||
}
|
||||
else if (type_name == "Windows.Storage.Streams.IBuffer")
|
||||
|
@ -1313,13 +1318,18 @@ namespace cppwinrt
|
|||
static_cast<D&>(*this) = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
return static_cast<D&>(*this);
|
||||
}
|
||||
|
||||
T operator*() const
|
||||
{
|
||||
return Current();
|
||||
}
|
||||
|
||||
void operator++(int)
|
||||
{
|
||||
++(*this);
|
||||
}
|
||||
)");
|
||||
}
|
||||
else if (type_name == "Windows.Foundation.Collections.IKeyValuePair`2")
|
||||
|
@ -1415,6 +1425,20 @@ namespace cppwinrt
|
|||
{
|
||||
w.write(R"( auto get() const;
|
||||
auto wait_for(Windows::Foundation::TimeSpan const& timeout) const;
|
||||
)");
|
||||
}
|
||||
else if (type_name == "Windows.Foundation.Collections.IIterable`1")
|
||||
{
|
||||
w.write(R"(
|
||||
auto begin() const;
|
||||
auto end() const;
|
||||
)");
|
||||
}
|
||||
else if (type_name == "Windows.UI.Xaml.Interop.IBindableIterable")
|
||||
{
|
||||
w.write(R"(
|
||||
auto begin() const;
|
||||
auto end() const;
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
@ -1426,11 +1450,23 @@ namespace cppwinrt
|
|||
if (type_name == "Windows.Foundation.Collections.IIterator`1")
|
||||
{
|
||||
w.write(R"(
|
||||
using iterator_concept = std::input_iterator_tag;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = T*;
|
||||
using reference = T&;
|
||||
using pointer = void;
|
||||
using reference = T;
|
||||
)");
|
||||
}
|
||||
else if (type_name == "Windows.UI.Xaml.Interop.IBindableIterator")
|
||||
{
|
||||
w.write(R"(
|
||||
using iterator_concept = std::input_iterator_tag;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
using value_type = Windows::Foundation::IInspectable;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = void;
|
||||
using reference = Windows::Foundation::IInspectable;
|
||||
)");
|
||||
}
|
||||
else if (type_name == "Windows.Foundation.IReference`1")
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
<ClInclude Include="..\strings\base_identity.h" />
|
||||
<ClInclude Include="..\strings\base_implements.h" />
|
||||
<ClInclude Include="..\strings\base_includes.h" />
|
||||
<ClInclude Include="..\strings\base_iterator.h" />
|
||||
<ClInclude Include="..\strings\base_lock.h" />
|
||||
<ClInclude Include="..\strings\base_macros.h" />
|
||||
<ClInclude Include="..\strings\base_marshaler.h" />
|
||||
|
|
|
@ -163,6 +163,9 @@
|
|||
<ClInclude Include="..\strings\base_coroutine_system_winui.h">
|
||||
<Filter>strings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\strings\base_iterator.h">
|
||||
<Filter>strings</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="$(OutDir)version.rc" />
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace cppwinrt
|
|||
w.write(strings::base_chrono);
|
||||
w.write(strings::base_security);
|
||||
w.write(strings::base_std_hash);
|
||||
w.write(strings::base_iterator);
|
||||
w.write(strings::base_coroutine_threadpool);
|
||||
w.write(strings::base_natvis);
|
||||
w.write(strings::base_version);
|
||||
|
|
|
@ -9,6 +9,7 @@ if "%target_platform%"=="" set target_platform=x64
|
|||
if "%target_configuration%"=="" set target_configuration=Debug
|
||||
|
||||
call :run_test test
|
||||
call :run_test test_cpp20
|
||||
call :run_test test_win7
|
||||
call :run_test test_fast
|
||||
call :run_test test_slow
|
||||
|
|
|
@ -3,174 +3,15 @@ namespace winrt::impl
|
|||
{
|
||||
namespace wfc = Windows::Foundation::Collections;
|
||||
|
||||
template <typename T>
|
||||
struct fast_iterator
|
||||
template <typename D, typename T>
|
||||
auto consume_Windows_Foundation_Collections_IIterable<D, T>::begin() const
|
||||
{
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
using value_type = decltype(std::declval<T>().GetAt(0));
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type;
|
||||
|
||||
fast_iterator() noexcept : m_collection(nullptr), m_index(0) {}
|
||||
|
||||
fast_iterator(T const& collection, uint32_t const index) noexcept :
|
||||
m_collection(&collection),
|
||||
m_index(index)
|
||||
{}
|
||||
|
||||
fast_iterator& operator++() noexcept
|
||||
{
|
||||
++m_index;
|
||||
return*this;
|
||||
}
|
||||
|
||||
fast_iterator operator++(int) noexcept
|
||||
{
|
||||
auto previous = *this;
|
||||
++m_index;
|
||||
return previous;
|
||||
}
|
||||
|
||||
fast_iterator& operator--() noexcept
|
||||
{
|
||||
--m_index;
|
||||
return*this;
|
||||
}
|
||||
|
||||
fast_iterator operator--(int) noexcept
|
||||
{
|
||||
auto previous = *this;
|
||||
--m_index;
|
||||
return previous;
|
||||
}
|
||||
|
||||
fast_iterator& operator+=(difference_type n) noexcept
|
||||
{
|
||||
m_index += static_cast<uint32_t>(n);
|
||||
return*this;
|
||||
}
|
||||
|
||||
fast_iterator operator+(difference_type n) const noexcept
|
||||
{
|
||||
return fast_iterator(*this) += n;
|
||||
}
|
||||
|
||||
fast_iterator& operator-=(difference_type n) noexcept
|
||||
{
|
||||
return *this += -n;
|
||||
}
|
||||
|
||||
fast_iterator operator-(difference_type n) const noexcept
|
||||
{
|
||||
return *this + -n;
|
||||
}
|
||||
|
||||
difference_type operator-(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return static_cast<difference_type>(m_index) - static_cast<difference_type>(other.m_index);
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return m_collection->GetAt(m_index);
|
||||
}
|
||||
|
||||
reference operator[](difference_type n) const
|
||||
{
|
||||
return m_collection->GetAt(m_index + static_cast<uint32_t>(n));
|
||||
}
|
||||
|
||||
bool operator==(fast_iterator const& other) const noexcept
|
||||
{
|
||||
WINRT_ASSERT(m_collection == other.m_collection);
|
||||
return m_index == other.m_index;
|
||||
}
|
||||
|
||||
bool operator<(fast_iterator const& other) const noexcept
|
||||
{
|
||||
WINRT_ASSERT(m_collection == other.m_collection);
|
||||
return m_index < other.m_index;
|
||||
}
|
||||
|
||||
bool operator!=(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool operator>(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
bool operator<=(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
bool operator>=(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T const* m_collection{};
|
||||
uint32_t m_index{};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class has_GetAt
|
||||
{
|
||||
template <typename U, typename = decltype(std::declval<U>().GetAt(0))> static constexpr bool get_value(int) { return true; }
|
||||
template <typename> static constexpr bool get_value(...) { return false; }
|
||||
|
||||
public:
|
||||
|
||||
static constexpr bool value = get_value<T>(0);
|
||||
};
|
||||
|
||||
template <typename T, std::enable_if_t<!has_GetAt<T>::value, int> = 0>
|
||||
auto begin(T const& collection) -> decltype(collection.First())
|
||||
{
|
||||
auto result = collection.First();
|
||||
|
||||
if (!result.HasCurrent())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return result;
|
||||
return get_begin_iterator(static_cast<D const&>(*this));
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<!has_GetAt<T>::value, int> = 0>
|
||||
auto end([[maybe_unused]] T const& collection) noexcept -> decltype(collection.First())
|
||||
template <typename D, typename T>
|
||||
auto consume_Windows_Foundation_Collections_IIterable<D, T>::end() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
fast_iterator<T> begin(T const& collection) noexcept
|
||||
{
|
||||
return { collection, 0 };
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
fast_iterator<T> end(T const& collection)
|
||||
{
|
||||
return { collection, collection.Size() };
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
auto rbegin(T const& collection)
|
||||
{
|
||||
return std::make_reverse_iterator(end(collection));
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
auto rend(T const& collection)
|
||||
{
|
||||
return std::make_reverse_iterator(begin(collection));
|
||||
return get_end_iterator(static_cast<D const&>(*this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
|
||||
namespace winrt::impl
|
||||
{
|
||||
template <typename T>
|
||||
struct fast_iterator
|
||||
{
|
||||
using iterator_concept = std::random_access_iterator_tag;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
using value_type = decltype(std::declval<T>().GetAt(0));
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = void;
|
||||
using reference = value_type;
|
||||
|
||||
fast_iterator() noexcept = default;
|
||||
|
||||
fast_iterator(T const& collection, uint32_t const index) noexcept :
|
||||
m_collection(&collection),
|
||||
m_index(index)
|
||||
{}
|
||||
|
||||
fast_iterator& operator++() noexcept
|
||||
{
|
||||
++m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
fast_iterator operator++(int) noexcept
|
||||
{
|
||||
auto previous = *this;
|
||||
++m_index;
|
||||
return previous;
|
||||
}
|
||||
|
||||
fast_iterator& operator--() noexcept
|
||||
{
|
||||
--m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
fast_iterator operator--(int) noexcept
|
||||
{
|
||||
auto previous = *this;
|
||||
--m_index;
|
||||
return previous;
|
||||
}
|
||||
|
||||
fast_iterator& operator+=(difference_type n) noexcept
|
||||
{
|
||||
m_index += static_cast<uint32_t>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
fast_iterator operator+(difference_type n) const noexcept
|
||||
{
|
||||
return fast_iterator(*this) += n;
|
||||
}
|
||||
|
||||
fast_iterator& operator-=(difference_type n) noexcept
|
||||
{
|
||||
return *this += -n;
|
||||
}
|
||||
|
||||
fast_iterator operator-(difference_type n) const noexcept
|
||||
{
|
||||
return *this + -n;
|
||||
}
|
||||
|
||||
difference_type operator-(fast_iterator const& other) const noexcept
|
||||
{
|
||||
WINRT_ASSERT(m_collection == other.m_collection);
|
||||
return static_cast<difference_type>(m_index) - static_cast<difference_type>(other.m_index);
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return m_collection->GetAt(m_index);
|
||||
}
|
||||
|
||||
reference operator[](difference_type n) const
|
||||
{
|
||||
return m_collection->GetAt(m_index + static_cast<uint32_t>(n));
|
||||
}
|
||||
|
||||
bool operator==(fast_iterator const& other) const noexcept
|
||||
{
|
||||
WINRT_ASSERT(m_collection == other.m_collection);
|
||||
return m_index == other.m_index;
|
||||
}
|
||||
|
||||
bool operator<(fast_iterator const& other) const noexcept
|
||||
{
|
||||
WINRT_ASSERT(m_collection == other.m_collection);
|
||||
return m_index < other.m_index;
|
||||
}
|
||||
|
||||
bool operator>(fast_iterator const& other) const noexcept
|
||||
{
|
||||
WINRT_ASSERT(m_collection == other.m_collection);
|
||||
return m_index > other.m_index;
|
||||
}
|
||||
|
||||
bool operator!=(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool operator<=(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
bool operator>=(fast_iterator const& other) const noexcept
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
friend fast_iterator operator+(difference_type n, fast_iterator it) noexcept
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
friend fast_iterator operator-(difference_type n, fast_iterator it) noexcept
|
||||
{
|
||||
return it - n;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T const* m_collection = nullptr;
|
||||
uint32_t m_index = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class has_GetAt
|
||||
{
|
||||
template <typename U, typename = decltype(std::declval<U>().GetAt(0))> static constexpr bool get_value(int) { return true; }
|
||||
template <typename> static constexpr bool get_value(...) { return false; }
|
||||
|
||||
public:
|
||||
|
||||
static constexpr bool value = get_value<T>(0);
|
||||
};
|
||||
|
||||
template <typename T, std::enable_if_t<!has_GetAt<T>::value, int> = 0>
|
||||
auto get_begin_iterator(T const& collection) -> decltype(collection.First())
|
||||
{
|
||||
auto result = collection.First();
|
||||
|
||||
if (!result.HasCurrent())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<!has_GetAt<T>::value, int> = 0>
|
||||
auto get_end_iterator([[maybe_unused]] T const& collection) noexcept -> decltype(collection.First())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
fast_iterator<T> get_begin_iterator(T const& collection) noexcept
|
||||
{
|
||||
return { collection, 0 };
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
fast_iterator<T> get_end_iterator(T const& collection)
|
||||
{
|
||||
return { collection, collection.Size() };
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
auto rbegin(T const& collection)
|
||||
{
|
||||
return std::make_reverse_iterator(get_end_iterator(collection));
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<has_GetAt<T>::value, int> = 0>
|
||||
auto rend(T const& collection)
|
||||
{
|
||||
return std::make_reverse_iterator(get_begin_iterator(collection));
|
||||
}
|
||||
|
||||
using std::begin;
|
||||
using std::end;
|
||||
}
|
|
@ -125,6 +125,17 @@ namespace winrt::impl
|
|||
{
|
||||
static constexpr Windows::UI::Xaml::Interop::TypeKind value = Windows::UI::Xaml::Interop::TypeKind::Primitive;
|
||||
};
|
||||
|
||||
template <typename D>
|
||||
auto consume_Windows_UI_Xaml_Interop_IBindableIterable<D>::begin() const
|
||||
{
|
||||
return get_begin_iterator(static_cast<D const&>(*this));
|
||||
}
|
||||
template <typename D>
|
||||
auto consume_Windows_UI_Xaml_Interop_IBindableIterable<D>::end() const
|
||||
{
|
||||
return get_end_iterator(static_cast<D const&>(*this));
|
||||
}
|
||||
}
|
||||
|
||||
WINRT_EXPORT namespace winrt
|
||||
|
|
|
@ -44,8 +44,19 @@ TEST_CASE("fast_iterator")
|
|||
REQUIRE(value == 9);
|
||||
REQUIRE(vbegin[2] == 4);
|
||||
REQUIRE(vbegin + 2 > vbegin);
|
||||
REQUIRE(2 + vbegin > vbegin);
|
||||
REQUIRE(2 - (vbegin + 4) > vbegin);
|
||||
REQUIRE(vbegin < vbegin + 2);
|
||||
REQUIRE(vbegin + 2 - 2 == vbegin);
|
||||
REQUIRE(end(v) - begin(v) == v.Size());
|
||||
REQUIRE((begin(v) + 3)[-1] == 4);
|
||||
}
|
||||
{
|
||||
// ensure that importing std::begin and std::end does not break existing code
|
||||
using std::begin;
|
||||
using std::end;
|
||||
|
||||
auto v = winrt::single_threaded_vector<int>({ 9, 5, 4, 1, 1, 3 });
|
||||
REQUIRE(std::is_heap(begin(v), end(v)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
#include "winrt/base.h"
|
||||
|
||||
using namespace winrt;
|
||||
|
||||
int main(int const argc, char** argv)
|
||||
{
|
||||
init_apartment();
|
||||
return Catch::Session().run(argc, argv);
|
||||
}
|
||||
|
||||
CATCH_TRANSLATE_EXCEPTION(hresult_error const& e)
|
||||
{
|
||||
return to_string(e.message());
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
#include "pch.h"
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#pragma warning(4: 4458) // ensure we compile clean with this warning enabled
|
||||
|
||||
#define WINRT_LEAN_AND_MEAN
|
||||
#include <unknwn.h>
|
||||
#include "winrt/Windows.Foundation.Collections.h"
|
||||
#include "winrt/Windows.Foundation.Numerics.h"
|
||||
#include <winstring.h>
|
||||
#include "catch.hpp"
|
||||
|
||||
using namespace std::literals;
|
|
@ -0,0 +1,48 @@
|
|||
#include "pch.h"
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
|
||||
TEST_CASE("ranges")
|
||||
{
|
||||
{
|
||||
// random-access range algorithms
|
||||
auto v = winrt::single_threaded_vector<int>({ 9, 8, 9, 6, 5, 8, 9, 3, 5, 3, 5, 3, 4, 7, 2, 1, 2, 3, 1 });
|
||||
|
||||
const bool result = std::ranges::is_heap(v);
|
||||
|
||||
REQUIRE((result == true));
|
||||
}
|
||||
{
|
||||
// bidirectional range views
|
||||
auto v = winrt::single_threaded_vector<int>({ 1, 2, 3 });
|
||||
|
||||
std::vector<int> result;
|
||||
for (const int i : v | std::views::reverse)
|
||||
{
|
||||
result.push_back(i);
|
||||
}
|
||||
|
||||
REQUIRE((result == std::vector{ 3, 2, 1 }));
|
||||
}
|
||||
{
|
||||
// input range algorithms
|
||||
// decay to IIterable is important, we want to test the non-fast iterators.
|
||||
winrt::Windows::Foundation::Collections::IIterable<int> iterable = winrt::single_threaded_vector<int>({ 2, 3, 1 });
|
||||
|
||||
const int result = (std::ranges::max)(iterable);
|
||||
REQUIRE((result == 3));
|
||||
}
|
||||
{
|
||||
// input range views
|
||||
// decay to IIterable is important, we want to test the non-fast iterators.
|
||||
winrt::Windows::Foundation::Collections::IIterable<int> iterable = winrt::single_threaded_vector<int>({ 1, 2, 3 });
|
||||
|
||||
std::vector<int> result;
|
||||
for (const int i : iterable | std::views::transform([](int i) { return i * 2; }))
|
||||
{
|
||||
result.push_back(i);
|
||||
}
|
||||
|
||||
REQUIRE((result == std::vector{ 2, 4, 6 }));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,316 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|ARM">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|ARM64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}</ProjectGuid>
|
||||
<RootNamespace>unittests</RootNamespace>
|
||||
<ProjectName>test_cpp20</ProjectName>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(SolutionDir)\cppwinrt.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IntDir>$(OutDir)temp\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IntDir>$(OutDir)temp\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IntDir>$(OutDir)temp\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IntDir>$(OutDir)temp\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ranges.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
Загрузка…
Ссылка в новой задаче