Created
April 6, 2018 16:38
-
-
Save atilaneves/1744e95ea769c87ef8b710ce2b9013e4 to your computer and use it in GitHub Desktop.
C++ templates and D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
struct Foo { | |
T value; | |
T twice() const { return value * 2; } | |
}; | |
#if __clang__ | |
[[clang::optnone]] | |
#elif __GNUC__ | |
__attribute__((optimize("O0"))) | |
#endif | |
__attribute((used, noinline)) | |
static void instantiate() { | |
const auto t = Foo<int>{}.twice(); | |
(void)t; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern(C++) { | |
struct Foo(T) { | |
T value; | |
T twice() const; | |
} | |
} | |
void main() { | |
import std.stdio; | |
auto f = Foo!int(3); | |
writeln("f: ", f); | |
writeln("f.twice: ", f.twice); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment