@@ -194,7 +194,18 @@ namespace cppwinrt
194194
195195 [[nodiscard]] static finish_with wrap_impl_namespace (writer& w)
196196 {
197- auto format = R"( WINRT_EXPORT namespace winrt::impl
197+ auto format = R"( WINRT_EXPORT extern "C++" namespace winrt::impl
198+ {
199+ )" ;
200+
201+ w.write (format);
202+
203+ return { w, write_close_namespace };
204+ }
205+
206+ [[nodiscard]] static finish_with wrap_impl_namespace_without_export (writer& w)
207+ {
208+ auto format = R"( extern "C++" namespace winrt::impl
198209{
199210)" ;
200211
@@ -205,7 +216,7 @@ namespace cppwinrt
205216
206217 [[nodiscard]] static finish_with wrap_std_namespace (writer& w)
207218 {
208- w.write (R"( WINRT_EXPORT namespace std
219+ w.write (R"( extern "C++" namespace std
209220{
210221)" );
211222
@@ -214,7 +225,7 @@ namespace cppwinrt
214225
215226 [[nodiscard]] static finish_with wrap_type_namespace (writer& w, std::string_view const & ns)
216227 {
217- auto format = R"( WINRT_EXPORT namespace winrt::@
228+ auto format = R"( WINRT_EXPORT extern "C++" namespace winrt::@
218229{
219230)" ;
220231
@@ -225,7 +236,7 @@ namespace cppwinrt
225236
226237 [[nodiscard]] static finish_with wrap_type_namespace_without_export (writer& w, std::string_view const & ns)
227238 {
228- auto format = R"( namespace winrt::@
239+ auto format = R"( extern "C++" namespace winrt::@
229240{
230241)" ;
231242
@@ -1548,7 +1559,7 @@ namespace cppwinrt
15481559 }
15491560 }
15501561
1551- static void write_consume (writer& w, TypeDef const & type)
1562+ static void write_consume_type (writer& w, TypeDef const & type)
15521563 {
15531564 auto generics = type.GenericParam ();
15541565 auto guard{ w.push_generic_params (generics) };
@@ -1561,51 +1572,71 @@ namespace cppwinrt
15611572
15621573 auto type_namespace = type.TypeNamespace ();
15631574 auto impl_name = get_impl_name (type_namespace, type_name);
1564-
1575+
15651576 if (empty (generics))
15661577 {
1567- auto format = R"( template <typename D>
1578+ auto format = R"( template <typename D>
15681579 struct consume_%
15691580 {
15701581%%% };
1571- template <> struct consume<%>
1572- {
1573- template <typename D> using type = consume_%<D>;
1574- };
15751582)" ;
1576-
1577-
15781583 w.write (format,
1579- impl_name,
1580- bind_each<write_consume_declaration>(type.MethodList ()),
1581- bind<write_fast_consume_declarations>(type),
1582- bind<write_consume_extensions>(type),
1583- type,
1584- impl_name);
1584+ impl_name,
1585+ bind_each<write_consume_declaration>(type.MethodList ()),
1586+ bind<write_fast_consume_declarations>(type),
1587+ bind<write_consume_extensions>(type));
15851588 }
15861589 else
15871590 {
1588- auto format = R"( template <typename D, %>
1591+ auto format = R"( template <typename D, %>
15891592 struct consume_%
15901593 {
15911594%%% };
1592- template <%> struct consume<%>
1595+ )" ;
1596+ w.write (format,
1597+ bind<write_generic_typenames>(generics),
1598+ impl_name,
1599+ bind_each<write_consume_declaration>(type.MethodList ()),
1600+ bind<write_fast_consume_declarations>(type),
1601+ bind<write_consume_extensions>(type));
1602+ }
1603+ }
1604+
1605+ static void write_consume_specialization (writer& w, TypeDef const & type)
1606+ {
1607+ auto generics = type.GenericParam ();
1608+ auto guard{ w.push_generic_params (generics) };
1609+ auto type_name = type.TypeName ();
1610+
1611+ if (!empty (generics))
1612+ {
1613+ type_name = remove_tick (type_name);
1614+ }
1615+
1616+ auto type_namespace = type.TypeNamespace ();
1617+ auto impl_name = get_impl_name (type_namespace, type_name);
1618+
1619+ if (empty (generics))
1620+ {
1621+ auto format = R"( template <> struct consume<%>
1622+ {
1623+ template <typename D> using type = consume_%<D>;
1624+ };
1625+ )" ;
1626+ w.write (format, type, impl_name);
1627+ }
1628+ else
1629+ {
1630+ auto format = R"( template <%> struct consume<%>
15931631 {
15941632 template <typename D> using type = consume_%<D, %>;
15951633 };
15961634)" ;
1597-
1598-
15991635 w.write (format,
1600- bind<write_generic_typenames>(generics),
1601- impl_name,
1602- bind_each<write_consume_declaration>(type.MethodList ()),
1603- bind<write_fast_consume_declarations>(type),
1604- bind<write_consume_extensions>(type),
1605- bind<write_generic_typenames>(generics),
1606- type,
1607- impl_name,
1608- bind_list (" , " , generics));
1636+ bind<write_generic_typenames>(generics),
1637+ type,
1638+ impl_name,
1639+ bind_list (" , " , generics));
16091640 }
16101641 }
16111642
0 commit comments