Skip to content

Instantly share code, notes, and snippets.

@tomjnixon
Created October 3, 2014 21:06
Show Gist options
  • Save tomjnixon/755a3095b8a1d6965ae5 to your computer and use it in GitHub Desktop.
Save tomjnixon/755a3095b8a1d6965ae5 to your computer and use it in GitHub Desktop.
template <typename T>
struct Foo {
T *x;
Foo(T *x) : x(x) {}
// operator Foo<const T> () const { return Foo<const T>(x); }
};
template <typename T>
T func(Foo<const T> f, T *out) {
*out = *f.x;
}
template <typename T>
void wrapper(const T * const x, T *out) {
Foo<const T> f = {x};
func(f, out);
}
void library() {
const double x = 5;
double out;
wrapper(&x, &out);
}
int main(int argc, char **argv) {
double x = 0.0;
Foo<double> f = {&x};
double out;
func<double>(f, &out);
library();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment