Created
October 10, 2017 12:09
-
-
Save egpbos/71b7beb7f1ed85f6a9496aaf50e1ec73 to your computer and use it in GitHub Desktop.
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
#include <complex> | |
#include <iostream> | |
template <typename T> using real_t = T; | |
template < typename precision, template <typename> class input_t, template <typename> class output_t > | |
void do_stuff(input_t<precision> a, output_t<precision> b) { | |
std::cout << a + b << std::endl; | |
} | |
int main() { | |
real_t<double> a = 1.; | |
real_t<double> b = 2.; | |
std::complex<double> c {0., 10.}; | |
std::complex<double> d {0., 33.}; | |
do_stuff<double, real_t, real_t>(a, b); | |
do_stuff<double, real_t, std::complex>(a, c); | |
do_stuff<double, std::complex, std::complex>(c, d); | |
do_stuff<double, std::complex, real_t>(c, b); | |
/* prints: | |
3 | |
(1,10) | |
(0,43) | |
(2,10) */ | |
do_stuff(a, b); | |
do_stuff(a, c); | |
do_stuff(c, d); | |
do_stuff(c, b); | |
/* does not compile: | |
note: template argument deduction/substitution failed: | |
note: can't deduce a template for 'input_t<precision>' from non-template type 'double' */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment