typedefs
<cctype> predicates to strings.
bool isdigitstr(const std::string & str); bool isspacestr(const std::string & str);
and so on.
bool isdigitstr(const std::string & str)
for (unsigned i = 0; i < str.size(); i++)
if !std::isdigit(str[i])
return false
return true
bool isspacestr(const std::string & str)
for (unsigned i = 0; i < str.size(); i++)
if !std::isspace(str[i])
return false
return true
and so on.
open(), close(), read(), write(), ...
return-type-spec ( * fun-name ) ( argument-list-decls )
bool (* comp)(int x, int y)
declares a
comp that
int parameters and
bool value.
bool (* comp)(int, int)
typedefstypedef bool (* comp_fun)(int x, int y)
typedef name.
void sort(int a[], comp_fun less) { ... }
comp_fun orders[] = { less, equal, greater }
bool (* comp)(int, int) declares comp as a pointer to a
function accepting two ints and returning a bool.
bool * comp(int, int) declares comp as a function
accepting two ints and return a pointer to a bool.
int i; void (* f)(int x); std::cout << i; // whatever (* f)(3); // disaster
bool less(int x, int y) { . . . }
bool (* comp)(int x, int y) = &less;
void less1(int x, int y) { . . . }
bool less2(int x) { . . . }
bool less3(int x, float y) { . . . }
bool (* comp1)(int x, int y) = &less1;
bool (* comp2)(int x, int y) = &less2;
bool (* comp3)(int x, int y) = &less3;
* goes to the function to execute.
bool b = (* cmpr)(3, 4);
fp(...) to (* fp)(...).
bool b = cmpr(3, 4);
* must appear in function pointer declarations.
& is not necessary.
bool (* comp)(int x, int y) = less;
():: is highest).
(* comp)(1, 2)
is not the same as
* comp(1, 2), identical to * (comp(1, 2)).
() can be overloaded.
bool isstrkind(string str, int (* cp)(int))
for (unsigned i = 0; i < str.size(); i++)
if !cp(str[i])
return false
return true
isstrkind(str, isspace)
isstrkind(str, isdigit)
_if ones, in particular).
widget::
widget(args a, void (* err_fun)(args))
if terrible error
err_fun(a)
struct device_driver {
int (* open)(char * name, mode_t mode);
int (* close)(void);
int (* read)(char * data, unsigned size);
int (* write)(char * data, unsigned size);
}
device_driver disk_device_driver =
{ dsk_open, dsk_close, dsk_read, dsk_write }
device_driver tty_device_driver =
{ tty_open, tty_close, tty_read, tty_write }
void t(void) {
device_driver dd = disk_device_driver
(dd.open)("/dev/null", R_ONLY)
}
static void quit_action(...) {...}
static void read_action(...) {...}
static void send_action(...) {...}
static button
quit_button = new_button("quit", quit_action)
read_button = new_button("read", read_action)
send_button = new_button("send", send_action)
this come from?
.* and ->* syntax (neither overloadable).
operator () is much more fun, though.
This page last modified on 17 November 2003.