tinyformat
tinyformat copied to clipboard
Allow to print any free or member class pointer
fix #68 - Cannot print function pointer
#include<iostream>
#include "tinyformat.h"
struct test_debugger { void var() {} };
void fun_void_void(){};
void fun_void_double(double d){};
double fun_double_double(double d){return d;}
int main(void) {
int* var;
std::cout << std::boolalpha;
std::cout << tfm::format( "0. %s", &var ) << std::endl;
std::cout << tfm::format( "1. %s", &fun_void_void ) << std::endl;
std::cout << tfm::format( "2. %s", &fun_void_double ) << std::endl;
std::cout << tfm::format( "3. %s", &fun_double_double ) << std::endl;
std::cout << tfm::format( "4. %s", &test_debugger::var ) << std::endl;
return 0;
}
Prints:
$ g++ -o main.exe -g -ggdb test.cpp --std=c++98 && ./main.exe
0. 0xffffcbb0
1. 0x100401100
2. 0x100401107
3. 0x100401113
4. 0x100405f10
$ g++ -o main.exe -g -ggdb test.cpp --std=c++11 && ./main.exe
0. 0xffffcbb0
1. 0x100401100
2. 0x100401107
3. 0x100401113
4. 0x100405b70
Passing all tests now.