이 프로젝트에서는 C++ 11을 사용할 수 없으며 추가 종속성 (예 : 부스트)을 추가 할 수 없습니다.pre-C++에 대한 std :: bind 대체 11
내가 달성하기 위해 노력하고있어입니다 :
typedef void (*processorFunction)(int numItems, std::string* items);
class Files
{
public:
Files() : m_KVSeparator('='), m_ListSeparator(',') {}
~Files() {}
void ReadDataFile(std::string filename, std::map<std::string, processorFunction> processorFunctions);
char m_KVSeparator;
char m_ListSeparator;
};
void Files::ReadDataFile(std::string filename, std::map<std::string, processorFunction> processorFunctions)
{
// The file parsing and choosing of the function omitted for brevity:
processorFunction processor = ...;
int numItems = ...;
std::string* items = ...;
processor(numItems, items);
}
// Example parser:
void time_limit_parser(int& timeLimit, int numItems, std::string* items)
{
timeLimit = atoi(items[0].c_str());
}
int main()
{
// Omitted getting the global file manager pointer
Files* files = ...;
std::map<std::string, processorFunction> configProcessorFunctions;
int timeLimit;
// ****** WHAT GOES HERE? ******
files->ReadDataFile("config.dat", configProcessorFunctions);
}
나는 ****** WHAT GOES HERE? ******
줄에 무엇을 넣을까요되어 내 질문? 부분적으로 적용하기 위해 std :: bind를 사용할 것입니다 (la time_limit_parser(timeLimit)
). 그러나이 프로젝트에는 C++ 11을 사용할 수 없습니다.
C++ 11 이전부터 TR1은 이미'std :: tr1 :: bind'를 제공했습니다. 그게 당신에게 유효합니까? 그렇지 않다면 Boost에 의존성을 추가 할 수 없더라도 Boost의 구현을 자신의 프로젝트에 복사 할 수 있습니다. – hvd