Visual Studio 2008 C++ 응용 프로그램에서 boost :: phoenix lambda 표현으로 단항 Functor를 대체하고 싶습니다.boost :: phoenix 배우로 단항 Functor 바꾸기
필자의 경우 문자열이 포함 된 개체 목록이 있습니다. 지정된 객체와 일치하지 않는 문자열을 가진 모든 객체를 제거하고 싶습니다. 그래서 저는 다음과 같은 알고리즘을 사용합니다 :
struct Foo
{
std::string my_type;
};
struct NotMatchType
{
NotMatchType(const std::string& t) : t_(t) { };
bool operator()(const Foo& f) const
{
return f.my_type.compare(t_) != 0;
};
std::string t_;
};
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<Foo> list_of_foo;
/*populate with objects*/
std::string some_type = "some type";
list_of_foo.erase(
std::remove_if(list_of_foo.begin(),
list_of_foo.end(),
NotMatchType(some_type)),
list_of_foo.end());
return 0;
}
잘 작동합니다. 그러나,이 같은 간단한 람다 식으로 내 코드를 조금 정리하고 NotMatchType
펑 제거하기와 교체 싶습니다 분명히
using boost::phoenix::arg_names::arg1;
list_of_foo.erase(
std::remove_if(list_of_foo.begin(),
list_of_foo.end(),
arg1.my_type.compare(some_type) != 0),
list_of_foo.end());
,이 작동하지 않습니다.
나는 또한 시도 : (arg1->*&Foo::my_type).compare(some_type) != 0
무엇을 내가 부스트을하려면 어떻게해야합니까 : 피닉스 : 배우가 Foo
객체처럼?
'arg1'은 포인터 타입을 나타내지 않으므로'operator -> * '를 사용하면 잘못되었습니다. '(& arg1) -> * & Foo :: my_type! = ref (some_type)'가 작동해야합니다. – ildjarn
lambdas (C++ 11의 일부)는 비극적으로 Visual Studio 2008에서는 사용할 수 없습니다. – PaulH
@ildjarn 따라 가지 않습니다. 'operator -> *'가 오버로드되었습니다; 필자가 보여준 코드가 제 편에 컴파일됩니다. –