Created
February 9, 2014 21:24
-
-
Save Fiona-J-W/8906137 to your computer and use it in GitHub Desktop.
converting-variadics-wrapper
This file contains hidden or 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 <cstdio> // printf | |
struct mytype { | |
int value; | |
operator int() const {return value;} | |
}; | |
template<typename T> struct argument_type_helper{using type = T;}; | |
template<> struct argument_type_helper<mytype>{using type = int;}; | |
template<typename T> using argument_type = typename argument_type_helper<T>::type; | |
template<typename T> argument_type<T> argument_cast(const T& arg) {return arg;} | |
template<typename...Args> | |
void converting_printf(const char* format, const Args&...args) { | |
std::printf(format, argument_cast(args)...); | |
} | |
int main() { | |
mytype myvar{42}; | |
converting_printf("mytype: %d, some int: %d\n", myvar, 23); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
mytype: 42, some int: 23