Skip to content

Commit fd4b105

Browse files
authored
Workarounds to improve IntelliSense (#433)
1 parent 84095fb commit fd4b105

File tree

5 files changed

+68
-76
lines changed

5 files changed

+68
-76
lines changed

cppwinrt/code_writers.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ namespace cppwinrt
366366

367367
if (empty(generics))
368368
{
369-
auto format = R"( template <> inline constexpr auto& name_v<%>{ L"%.%" };
369+
auto format = R"( template <> inline constexpr auto& name_v<%> = L"%.%";
370370
)";
371371

372372
w.write(format, type, type_name.name_space, type_name.name);
373373
}
374374
else
375375
{
376-
auto format = R"( template <%> inline constexpr auto name_v<%>{ zcombine(L"%.%<"%, L">") };
376+
auto format = R"( template <%> inline constexpr auto name_v<%> = zcombine(L"%.%<"%, L">");
377377
)";
378378

379379
w.write(format,
@@ -916,8 +916,9 @@ namespace cppwinrt
916916
auto method_name = get_name(method);
917917
auto type = method.Parent();
918918

919-
w.write(" %auto %(%) const%;\n",
919+
w.write(" %WINRT_IMPL_AUTO(%) %(%) const%;\n",
920920
is_get_overload(method) ? "[[nodiscard]] " : "",
921+
signature.return_signature(),
921922
method_name,
922923
bind<write_consume_params>(signature),
923924
is_noexcept(method) ? " noexcept" : "");
@@ -1054,15 +1055,15 @@ namespace cppwinrt
10541055

10551056
if (is_noexcept(method))
10561057
{
1057-
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
1058+
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
10581059
{%
10591060
WINRT_VERIFY_(0, WINRT_IMPL_SHIM(%)->%(%));%
10601061
}
10611062
)";
10621063
}
10631064
else
10641065
{
1065-
format = R"( template <typename D%> auto consume_%<D%>::%(%) const
1066+
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const
10661067
{%
10671068
check_hresult(WINRT_IMPL_SHIM(%)->%(%));%
10681069
}
@@ -1071,6 +1072,7 @@ namespace cppwinrt
10711072

10721073
w.write(format,
10731074
bind<write_comma_generic_typenames>(generics),
1075+
signature.return_signature(),
10741076
type_impl_name,
10751077
bind<write_comma_generic_types>(generics),
10761078
method_name,
@@ -1118,13 +1120,14 @@ namespace cppwinrt
11181120
// return static_cast<% const&>(*this).%(%);
11191121
//
11201122

1121-
std::string_view format = R"( inline auto %::%(%) const%
1123+
std::string_view format = R"( inline WINRT_IMPL_AUTO(%) %::%(%) const%
11221124
{
11231125
return [&](% const& winrt_impl_base) { return winrt_impl_base.%(%); }(*this);
11241126
}
11251127
)";
11261128

11271129
w.write(format,
1130+
signature.return_signature(),
11281131
class_type.TypeName(),
11291132
method_name,
11301133
bind<write_consume_params>(signature),

strings/base_foundation.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
102102

103103
namespace winrt::impl
104104
{
105-
template <> inline constexpr auto& name_v<Windows::Foundation::Point>{ L"Windows.Foundation.Point" };
106-
template <> inline constexpr auto& name_v<Windows::Foundation::Size>{ L"Windows.Foundation.Size" };
107-
template <> inline constexpr auto& name_v<Windows::Foundation::Rect>{ L"Windows.Foundation.Rect" };
105+
template <> inline constexpr auto& name_v<Windows::Foundation::Point> = L"Windows.Foundation.Point";
106+
template <> inline constexpr auto& name_v<Windows::Foundation::Size> = L"Windows.Foundation.Size";
107+
template <> inline constexpr auto& name_v<Windows::Foundation::Rect> = L"Windows.Foundation.Rect";
108108

109109
template <> struct category<Windows::Foundation::Point>
110110
{
@@ -123,13 +123,13 @@ namespace winrt::impl
123123

124124
#ifdef WINRT_IMPL_NUMERICS
125125

126-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float2>{ L"Windows.Foundation.Numerics.Vector2" };
127-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3>{ L"Windows.Foundation.Numerics.Vector3" };
128-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4>{ L"Windows.Foundation.Numerics.Vector4" };
129-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3x2>{ L"Windows.Foundation.Numerics.Matrix3x2" };
130-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4x4>{ L"Windows.Foundation.Numerics.Matrix4x4" };
131-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::quaternion>{ L"Windows.Foundation.Numerics.Quaternion" };
132-
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::plane>{ L"Windows.Foundation.Numerics.Plane" };
126+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float2> = L"Windows.Foundation.Numerics.Vector2";
127+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3> = L"Windows.Foundation.Numerics.Vector3";
128+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4> = L"Windows.Foundation.Numerics.Vector4";
129+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3x2> = L"Windows.Foundation.Numerics.Matrix3x2";
130+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4x4> = L"Windows.Foundation.Numerics.Matrix4x4";
131+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::quaternion> = L"Windows.Foundation.Numerics.Quaternion";
132+
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::plane> = L"Windows.Foundation.Numerics.Plane";
133133

134134
template <> struct category<Windows::Foundation::Numerics::float2>
135135
{

strings/base_identity.h

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ namespace winrt::impl
271271
}
272272

273273
template <size_t Size>
274-
constexpr std::array<uint32_t, 5> process_msg_block(std::array<uint8_t, Size> const& input, uint32_t start_pos, std::array<uint32_t, 5> const& intermediate_hash) noexcept
274+
constexpr std::array<uint32_t, 5> process_msg_block(std::array<uint8_t, Size> const& input, size_t start_pos, std::array<uint32_t, 5> const& intermediate_hash) noexcept
275275
{
276276
uint32_t const K[4] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 };
277277
std::array<uint32_t, 80> W = {};
278278

279-
uint32_t t = 0;
279+
size_t t = 0;
280280
uint32_t temp = 0;
281281

282282
for (t = 0; t < 16; t++)
@@ -357,13 +357,13 @@ namespace winrt::impl
357357
}
358358

359359
template <size_t Size, size_t RemainingSize, size_t... Index>
360-
constexpr std::array<uint8_t, RemainingSize + 1> make_remaining([[maybe_unused]] std::array<uint8_t, Size> const& input, [[maybe_unused]] uint32_t start_pos, std::index_sequence<Index...>) noexcept
360+
constexpr std::array<uint8_t, RemainingSize + 1> make_remaining([[maybe_unused]] std::array<uint8_t, Size> const& input, [[maybe_unused]] size_t start_pos, std::index_sequence<Index...>) noexcept
361361
{
362362
return { input[Index + start_pos]..., 0x80 };
363363
}
364364

365365
template <size_t Size>
366-
constexpr auto make_remaining(std::array<uint8_t, Size> const& input, uint32_t start_pos) noexcept
366+
constexpr auto make_remaining(std::array<uint8_t, Size> const& input, size_t start_pos) noexcept
367367
{
368368
constexpr auto remaining_size = Size % 64;
369369
return make_remaining<Size, remaining_size>(input, start_pos, std::make_index_sequence<remaining_size>());
@@ -409,7 +409,7 @@ namespace winrt::impl
409409
constexpr auto calculate_sha1(std::array<uint8_t, Size> const& input) noexcept
410410
{
411411
std::array<uint32_t, 5> intermediate_hash{ 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 };
412-
uint32_t i = 0;
412+
size_t i = 0;
413413

414414
while (i + 64 <= Size)
415415
{
@@ -536,44 +536,44 @@ namespace winrt::impl
536536
constexpr guid generic_guid_v{};
537537

538538
template <typename T>
539-
constexpr auto& basic_signature_v{""};
540-
541-
template <> inline constexpr auto& basic_signature_v<bool>{"b1"};
542-
template <> inline constexpr auto& basic_signature_v<int8_t>{"i1"};
543-
template <> inline constexpr auto& basic_signature_v<int16_t>{"i2"};
544-
template <> inline constexpr auto& basic_signature_v<int32_t>{"i4"};
545-
template <> inline constexpr auto& basic_signature_v<int64_t>{"i8"};
546-
template <> inline constexpr auto& basic_signature_v<uint8_t>{"u1"};
547-
template <> inline constexpr auto& basic_signature_v<uint16_t>{"u2"};
548-
template <> inline constexpr auto& basic_signature_v<uint32_t>{"u4"};
549-
template <> inline constexpr auto& basic_signature_v<uint64_t>{"u8"};
550-
template <> inline constexpr auto& basic_signature_v<float>{"f4"};
551-
template <> inline constexpr auto& basic_signature_v<double>{"f8"};
552-
template <> inline constexpr auto& basic_signature_v<char16_t>{"c2"};
553-
template <> inline constexpr auto& basic_signature_v<guid>{"g16"};
554-
template <> inline constexpr auto& basic_signature_v<hstring>{"string"};
555-
template <> inline constexpr auto& basic_signature_v<Windows::Foundation::IInspectable>{"cinterface(IInspectable)"};
556-
557-
template <> inline constexpr auto& name_v<bool>{ L"Boolean" };
558-
template <> inline constexpr auto& name_v<int8_t>{ L"Int8" };
559-
template <> inline constexpr auto& name_v<int16_t>{ L"Int16" };
560-
template <> inline constexpr auto& name_v<int32_t>{ L"Int32" };
561-
template <> inline constexpr auto& name_v<int64_t>{ L"Int64" };
562-
template <> inline constexpr auto& name_v<uint8_t>{ L"UInt8" };
563-
template <> inline constexpr auto& name_v<uint16_t>{ L"UInt16" };
564-
template <> inline constexpr auto& name_v<uint32_t>{ L"UInt32" };
565-
template <> inline constexpr auto& name_v<uint64_t>{ L"UInt64" };
566-
template <> inline constexpr auto& name_v<float>{ L"Single" };
567-
template <> inline constexpr auto& name_v<double>{ L"Double" };
568-
template <> inline constexpr auto& name_v<char16_t>{ L"Char16" };
569-
template <> inline constexpr auto& name_v<guid>{ L"Guid" };
570-
template <> inline constexpr auto& name_v<hstring>{ L"String" };
571-
template <> inline constexpr auto& name_v<hresult>{ L"Windows.Foundation.HResult" };
572-
template <> inline constexpr auto& name_v<event_token>{ L"Windows.Foundation.EventRegistrationToken" };
573-
template <> inline constexpr auto& name_v<Windows::Foundation::IInspectable>{ L"Object" };
574-
template <> inline constexpr auto& name_v<Windows::Foundation::TimeSpan>{ L"Windows.Foundation.TimeSpan" };
575-
template <> inline constexpr auto& name_v<Windows::Foundation::DateTime>{ L"Windows.Foundation.DateTime" };
576-
template <> inline constexpr auto& name_v<IAgileObject>{ L"IAgileObject" };
539+
constexpr auto& basic_signature_v = "";
540+
541+
template <> inline constexpr auto& basic_signature_v<bool> = "b1";
542+
template <> inline constexpr auto& basic_signature_v<int8_t> = "i1";
543+
template <> inline constexpr auto& basic_signature_v<int16_t> = "i2";
544+
template <> inline constexpr auto& basic_signature_v<int32_t> = "i4";
545+
template <> inline constexpr auto& basic_signature_v<int64_t> = "i8";
546+
template <> inline constexpr auto& basic_signature_v<uint8_t> = "u1";
547+
template <> inline constexpr auto& basic_signature_v<uint16_t> = "u2";
548+
template <> inline constexpr auto& basic_signature_v<uint32_t> = "u4";
549+
template <> inline constexpr auto& basic_signature_v<uint64_t> = "u8";
550+
template <> inline constexpr auto& basic_signature_v<float> = "f4";
551+
template <> inline constexpr auto& basic_signature_v<double> = "f8";
552+
template <> inline constexpr auto& basic_signature_v<char16_t> = "c2";
553+
template <> inline constexpr auto& basic_signature_v<guid> = "g16";
554+
template <> inline constexpr auto& basic_signature_v<hstring> = "string";
555+
template <> inline constexpr auto& basic_signature_v<Windows::Foundation::IInspectable> = "cinterface(IInspectable)";
556+
557+
template <> inline constexpr auto& name_v<bool> = L"Boolean";
558+
template <> inline constexpr auto& name_v<int8_t> = L"Int8";
559+
template <> inline constexpr auto& name_v<int16_t> = L"Int16";
560+
template <> inline constexpr auto& name_v<int32_t> = L"Int32";
561+
template <> inline constexpr auto& name_v<int64_t> = L"Int64";
562+
template <> inline constexpr auto& name_v<uint8_t> = L"UInt8";
563+
template <> inline constexpr auto& name_v<uint16_t> = L"UInt16";
564+
template <> inline constexpr auto& name_v<uint32_t> = L"UInt32";
565+
template <> inline constexpr auto& name_v<uint64_t> = L"UInt64";
566+
template <> inline constexpr auto& name_v<float> = L"Single";
567+
template <> inline constexpr auto& name_v<double> = L"Double";
568+
template <> inline constexpr auto& name_v<char16_t> = L"Char16";
569+
template <> inline constexpr auto& name_v<guid> = L"Guid";
570+
template <> inline constexpr auto& name_v<hstring> = L"String";
571+
template <> inline constexpr auto& name_v<hresult> = L"Windows.Foundation.HResult";
572+
template <> inline constexpr auto& name_v<event_token> = L"Windows.Foundation.EventRegistrationToken";
573+
template <> inline constexpr auto& name_v<Windows::Foundation::IInspectable> = L"Object";
574+
template <> inline constexpr auto& name_v<Windows::Foundation::TimeSpan> = L"Windows.Foundation.TimeSpan";
575+
template <> inline constexpr auto& name_v<Windows::Foundation::DateTime> = L"Windows.Foundation.DateTime";
576+
template <> inline constexpr auto& name_v<IAgileObject> = L"IAgileObject";
577577

578578
template <> struct category<bool> { using type = basic_category; };
579579
template <> struct category<int8_t> { using type = basic_category; };

strings/base_macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
#define WINRT_IMPL_SHIM(...) (*(abi_t<__VA_ARGS__>**)&static_cast<__VA_ARGS__ const&>(static_cast<D const&>(*this)))
1717

18+
#ifdef __INTELLISENSE__
19+
#define WINRT_IMPL_AUTO(...) __VA_ARGS__
20+
#else
21+
#define WINRT_IMPL_AUTO(...) auto
22+
#endif
23+
1824
// Note: this is a workaround for a false-positive warning produced by the Visual C++ 15.9 compiler.
1925
#pragma warning(disable : 5046)
2026

test/old_tests/UnitTests/IReference.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,6 @@ TEST_CASE("IReference guids")
3030
REQUIRE(guid_of<IReference<Numerics::float4x4>>() == ireference_matrix4x4);
3131
REQUIRE(guid_of<IReference<Numerics::plane>>() == ireference_plane);
3232
REQUIRE(guid_of<IReference<Numerics::quaternion>>() == ireference_quaternion);
33-
34-
REQUIRE(guid_of<IReference<bool>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<bool>)));
35-
REQUIRE(guid_of<IReference<uint8_t>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<uint8_t>)));
36-
REQUIRE(guid_of<IReference<int16_t>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<int16_t>)));
37-
REQUIRE(guid_of<IReference<uint32_t>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<uint32_t>)));
38-
REQUIRE(guid_of<IReference<int32_t>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<int32_t>)));
39-
REQUIRE(guid_of<IReference<uint64_t>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<uint64_t>)));
40-
REQUIRE(guid_of<IReference<int64_t>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<int64_t>)));
41-
REQUIRE(guid_of<IReference<float>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<float>)));
42-
REQUIRE(guid_of<IReference<double>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<double>)));
43-
REQUIRE(guid_of<IReference<guid>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<GUID>)));
44-
45-
REQUIRE(guid_of<IReference<winrt::Windows::Foundation::Point>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::Point>)));
46-
REQUIRE(guid_of<IReference<winrt::Windows::Foundation::Rect>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::Rect>)));
47-
48-
REQUIRE(guid_of<IReference<winrt::Windows::Foundation::DateTime>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::DateTime>)));
49-
REQUIRE(guid_of<IReference<winrt::Windows::Foundation::TimeSpan>>() == guid(__uuidof(::ABI::Windows::Foundation::IReference<::ABI::Windows::Foundation::TimeSpan>)));
5033
}
5134

5235
TEST_CASE("IReference, constructor and getter")

0 commit comments

Comments
 (0)