문제

Is there an algorithm or helper method in the boost library to search a vector of boost::tuple objects? Here is my code:

typedef boost::tuple<int, char const*, char const*> Tuple;
typedef std::vector<Tuple> ErrorStringMap;

ErrorStringMap mystrings = tuple_list_of
    (10, "10", "ten") 
    (20, "20", "twenty") 
    (30, "30", "thirty") 
    (40, "40", "fourty");

I want to search the vector of tuples and find the first tuple with the value 20 as the first element in the tuple. I want to access that tuple's 2nd and 3rd elements.

도움이 되었습니까?

해결책

ildjarn answered this in the list of comments below my question, however he did not post as an answer, so I will do it for him:

Phoenix's placeholders are in boost::phoenix::placeholders. Also, if you're using Phoenix, you don't need bind for this -- with the proper includes, at_c<0>(_1) == 20 works.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top