Reputation: 954
I wanted a means of allowing terminfo
escape sequences (esp. resulting from calls to tparm()
) to be stored in strings, so I wrote this wrapper class.
class tputs_wrapper {
private:
static string *current;
public:
using putchar_like=int (*)(int);
tputs_wrapper(string &s){
s.clear();
current=&s;
}
static int putchar(int ch){
*current+=static_cast<unsigned char>(ch);
return ch;
}
operator putchar_like(){ return putchar; }
};
string *tputs_wrapper::current=nullptr;
Which can be used as follows (crude example).
tputs(tparm(set_a_foreground, 196), 1, tputs_wrapper(sp)); // Invokes the type conversion operator for tupts' thrid arg.
tputs(tparm(exit_attribute_mode), 1, tputs_wrapper(ep)); // Ditto.
cout << sp << "Pink." << ep << "\nNormal\n";
Question: Is there a way of declaring the operator that allows the object of that class to be interpreted as a pointer to a function taking an int
and returning int
without resorting to the type alias putchar_like
?
Upvotes: 0
Views: 56