swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.51k stars 10.35k forks source link

[SR-13261] [C++] Allow instantiating C++ templates from Swift #55701

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13261
Radar rdar://problem/83423218
Original Reporter hlopko (JIRA User)
Type New Feature
Status In Progress
Resolution
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | New Feature, CxxInterop | |Assignee | scentini (JIRA) | |Priority | Medium | md5: 55b08f175ae8509127468b5b5b9af809

Issue Description:

I.e. allow using following C++ header:

template<class T>
struct Tpl {
  inline int callMethod() const {
    return T::method();
  }
};

struct Arg {
  static int method() { return 6; }
};

in Swift like:

print(Tpl<Arg>().callMethod())

In the initial version we'll only support passing C++ types as template arguments, plus a small hardcoded set of Swift primitive types (converted to corresponding C++ types behind the scenes).

swift-ci commented 4 years ago

Comment by Marcel Hlopko (JIRA)

PR https://github.com/apple/swift/pull/33284 implements basic support for instantiating C++ class templates from Swift.

What doesn't work is:

zoecarver commented 3 years ago

@swift-ci create