Reputation:
How to determine / check whether a function argument is given or omitted in compile time?
bool a_function(char* b, size_t len=0) {
// no run time check such as if (len ......
// just compile time check
// ...
}
How to realize it?
Upvotes: 3
Views: 92
Reputation: 172894
No, there's no way to know (even at run-time) the argument was specified or not for parameter with default argument in the function.
You can apply overloading, e.g.
bool a_function(char* b, size_t len) {
// len is specified
// do something...
}
bool a_function(char* b) {
// len is not specified
// do something else...
// or call a_function with len=0 (the default value) if satisfying the requirement
}
Upvotes: 6