Changeset 3466
- Timestamp:
- Feb 10, 2016, 4:39:38 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/utility.cc
r3417 r3466 78 78 void test_compose_functors(test::Suite& suite); 79 79 void test_dereferencer(test::Suite& suite); 80 void test_ticket842(test::Suite& suite); 80 81 81 82 int main(int argc, char* argv[]) … … 230 231 test_rename(suite); 231 232 test_replace(suite); 233 test_ticket842(suite); 232 234 233 235 return suite.return_value(); … … 757 759 suite.err() << "error: " << s << "\n"; 758 760 } 761 762 763 void test_ticket842(test::Suite& suite) 764 { 765 suite.out() << "test_ticket842\n"; 766 std::vector<std::pair<std::string, int> > data; 767 data.push_back(std::make_pair("Orange", 2)); 768 data.push_back(std::make_pair("Orange", 1)); 769 data.push_back(std::make_pair("Apple", 10)); 770 771 typedef utility::PairFirst<const std::pair<std::string, int> > PF; 772 typedef std::less<std::string> strLess; 773 utility::compose_f_gx_hy<strLess, PF, PF> compare; 774 // stable sort should shuffle 'Apple' first, and then keep the order 775 // of the equaivalent 'Orange' elements, i.e., <Orange, 2> should stay 776 // before <Orange, 1>. 777 std::stable_sort(data.begin(), data.end(), compare); 778 if (!suite.add(data[0].first == "Apple")) 779 suite.err() << "incorrect data[0].first: " << data[0].first << "\n"; 780 if (!suite.add(data[1].first == "Orange")) 781 suite.err() << "incorrect data[1].first: " << data[1].first << "\n"; 782 if (!suite.add(data[1].second == 2)) 783 suite.err() << "incorrect data[1].second: " << data[1].second << "\n"; 784 } -
trunk/yat/utility/stl_utility.h
r3417 r3466 160 160 161 161 \see compose_f_gxy, compose_f_gx, and compose_f_gx_hx 162 163 Here is an example using the class to construct a functor that 164 compares std::pairs ignoring \c second. 165 166 \code 167 vector<pair<string, foo> > data; 168 data.push_back(make_pair("Orange", foo(2)); 169 data.push_back(make_pair("Orange", foo(1)); 170 data.push_back(make_pair("Apple", foo(10)); 171 typedef PairFirst<const pair<string, foo> > PF; 172 compose_f_gx_hy<less<string>, PF, PF> compare; 173 sort(data.begin(), data.end(), compare); 174 \endcode 175 162 176 */ 163 177 template<class F, class G, class H>
Note: See TracChangeset
for help on using the changeset viewer.