sos who can help me ......

i dunno the significance of the following code , look at the following...code

#include <ystdex/container.hpp> // the question is that i can't find the file in my Xcode (the version of IDE: 4.6.1) and i dunno the significance of the Header file ...

std::string _Str(" 123ddfg56"); //create the global variable

ystdex::erase_all_if(s, static_cast<int(&)(int)>(std::isdigit));// i dunno the significance of int(&) int and std::isdigit

----
// <ystdex/container.hpp>:
#include <algorithm>
namespace ystdex
{
template<typename _tRange, typename _fPredicate>
void
erase_all_if(_tRange& c, _fPredicate pred)
{
c.erase(std::remove_if(begin(c), end(c), pred), end(c));
}
}

thx 4 everybody who will help me
Its cryptic and whoever made it probrably doesnt know what it does, just bad api design when the function name doesn't imply anything what the function does and there are unnecessary" _" prefixes. You should look up what std::remove_if does, it must be some condition. Sorry I don't know. std::isdigit is used wrong since it is a function"()" without being properly called. It evaluates if a character is numerical "0-9" digit.
Last edited on
who can help me .....
noooooo!! the afore code was to erase the digital in object _Str ,but i dunno the significance of "ystdex/container.hpp" header file ,the key question that i can't find the .hpp
Did you tell the linker where your code directories are? It won't work If the compiler and linker doesnt know where to look for the files.
ystdex::erase_all_if(s, static_cast<int(&)(int)>(std::isdigit));// i dunno the significance of int(&) int and std::isdigit


It's a disambiguating cast. There are two kinds of std::isdigit in the C++ standard library, one that takes an int and returns an int, another one that takes any char type and a locale and returns a bool.

Normally, when you put a name of a function in an expression like that, the compiler would create a pointer to it and pass that pointer as the argument to erase_all_if, but since the name std::isdigit stands for more than one function, it doesn't know whose address you want. The cast is one of the possible ways to resolve this ambiguity.
ah its a predicate sorry. Try to make it a function ptr instead of a reference.

1
2
3
typedef int (*pfpredicate)(int);

foo<pfpredicate>(...,...);
Topic archived. No new replies allowed.