Skip to content

Instantly share code, notes, and snippets.

@atilaneves
Created April 6, 2018 16:38
Show Gist options
  • Save atilaneves/1744e95ea769c87ef8b710ce2b9013e4 to your computer and use it in GitHub Desktop.
Save atilaneves/1744e95ea769c87ef8b710ce2b9013e4 to your computer and use it in GitHub Desktop.
C++ templates and D
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;
}
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