Esempio n. 1
1
void basic_algo(){
    cout<<endl<<"basic_algo :"<<endl;
    int ia[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8 };
    vector<int> iv1(ia,ia+5);	vector<int> iv2(ia,ia+9);
    cout<<iv1<<endl<<iv2<<endl;
    pair<vector<int>::iterator,vector<int>::iterator> p = mismatch(iv1.begin(),iv1.end(),iv2.begin());	//返回在游标的哪个位置不匹配
    if(p.first != iv1.end())	cout<<*(p.first)<<endl;
    if(p.second != iv2.end())	cout<<*(p.second)<<endl;

    cout<<equal(iv1.begin(),iv1.end(),iv2.begin())<<endl;	//比较容器内内容
    cout<<equal(iv1.begin(),iv1.end(),&ia[3])<<endl;
    cout<<equal(iv1.begin(),iv1.end(),&ia[3],less<int>())<<endl;

    fill(iv1.begin(),iv1.end(),9);			//区间填充
    cout<<iv1<<endl;
    fill_n(iv1.begin(), 3, 7);		//区间n填充
    cout<<iv1<<endl;
    vector<int>::iterator iter1,iter2;
    iter1 = iter2 = iv1.begin();
    advance(iter2,3);						//游标向前移动
    iter_swap(iter1,iter2);					//交换两个游标内容
    cout<<iv1<<endl;
    swap(*iv1.begin(),*iv2.begin());	//交换两个游标内容
    cout<<iv1<<endl<<iv2<<endl;
    string stra1[] = {"jk","jK1","jk2"};	string stra2[] = {"jk","jk1","jk3"};
    cout<<lexicographical_compare(stra1,stra1+2,stra2,stra2+2)<<endl;
    cout<<lexicographical_compare(stra1,stra1+2,stra2,stra2+2,greater<string>())<<endl;

    copy(iv2.begin()+1,iv2.end(),iv2.begin());		//全部元素向前移一格
    cout<<iv2<<endl;
    copy_backward(iv2.begin(),iv2.end()-1,iv2.end());	//全部元素向后移一格
    cout<<iv2<<endl;
}
Esempio n. 2
0
int main()
{
	string arr1[] = { "Piglet", "Pooh", "Tigger" };
	string arr2[] = { "Piglet", "Pooch", "Eeyore" };
		
	bool res;
		
	// evaluates to false at second element
	// Pooch is less than Pooh
	// would also evaluate false at 3rd element

	res = lexicographical_compare( arr1, arr1+3,
				       arr2, arr2+3 );

	assert( res == false );
		
	// evaluates to true: each element of ilist2
	// has a length less-than or equal to the
	// associated ilist1 element

	list< string, allocator > ilist1( arr1, arr1+3 );
	list< string, allocator > ilist2( arr2, arr2+3 );
		
	res = lexicographical_compare( 
	         ilist1.begin(), ilist1.end(), 
	         ilist2.begin(), ilist2.end(), size_compare() );
		
	assert( res == true );
	
	cout << "ok: lexicographical_compare succeeded!\n";
}
Esempio n. 3
0
 inline bool ilexicographical_compare(
     const Range1T& Arg1,
     const Range2T& Arg2,
     const std::locale& Loc=std::locale())
 {
     return lexicographical_compare(Arg1, Arg2, is_iless(Loc));
 }
		void RunLexicographicalCompareCallback(CompareDataType _Type)
		{
			{  // seq
				LexicographicalCompareAlgoTest<_IterCat> _Alg(_Type);
				_Alg.set_result(lexicographical_compare(seq, _Alg.begin_in(), _Alg.end_in(), _Alg.begin_dest(), _Alg.end_dest(), _Alg.callback()));
			}

			{  //par
				LexicographicalCompareAlgoTest<_IterCat> _Alg(_Type);
				_Alg.set_result(lexicographical_compare(par, _Alg.begin_in(), _Alg.end_in(), _Alg.begin_dest(), _Alg.end_dest(), _Alg.callback()));
			}

			{  //vec
				LexicographicalCompareAlgoTest<_IterCat> _Alg(_Type);
				_Alg.set_result(lexicographical_compare(vec, _Alg.begin_in(), _Alg.end_in(), _Alg.begin_dest(), _Alg.end_dest(), _Alg.callback()));
			}
		}
bool	DeviceName::operator<(const DeviceName& other) const {
	if (type() < other.type()) {
		return true;
	}
	if (type() == other.type()) {
		return lexicographical_compare(begin(), end(),
						other.begin(), other.end());
	}
	return false;
}
Esempio n. 6
0
int main ()
{
  bool before =
    lexicographical_compare (n1, n1 + size,
                             n2, n2 + size,
                             greater<char>());
  if (before)
    cout << n1 << " is after " << n2 << endl;
  else
    cout << n2 << " is after " << n1 << endl;
  return 0;
}
Esempio n. 7
0
int CSString::compare(const CSString &s1, const CSString &s2)
{
	if (lexicographical_compare(s1._deqCustString->begin(), s1._deqCustString->end(), s2._deqCustString->begin(), s2._deqCustString->end()))
		return -1;
	if (s1.size() != s2.size())
		return 1;
	for (int i = 0; i < s1.size(); i++)
	{
		if (s1[i] != s2[i])
			return 1;
	}
	return 0;
}
bool IsLessRegister::operator ()(const CTrieNodeBuild* pNodeNo1, const CTrieNodeBuild* pNodeNo2) const
{
	if (pNodeNo1->m_bFinal != pNodeNo2->m_bFinal)
		return pNodeNo1->m_bFinal < pNodeNo2->m_bFinal;

	assert (pNodeNo1->m_FirstChildNo == pNodeNo2->m_FirstChildNo);
	if (pNodeNo1->m_FirstChildNo == 0xff) return false;
	if (pNodeNo1->m_Children[pNodeNo1->m_FirstChildNo] < pNodeNo2->m_Children[pNodeNo2->m_FirstChildNo]) 
		return true;
	if (pNodeNo1->m_Children[pNodeNo1->m_FirstChildNo] > pNodeNo2->m_Children[pNodeNo2->m_FirstChildNo]) 
		return false;


	assert (pNodeNo1->m_SecondChildNo == pNodeNo1->m_SecondChildNo);
	if (pNodeNo1->m_SecondChildNo == 0xff) return false;

	return lexicographical_compare
			(pNodeNo1->m_Children+pNodeNo1->m_SecondChildNo, pNodeNo1->m_Children+MaxAlphabetSize,
			pNodeNo2->m_Children+pNodeNo2->m_SecondChildNo, pNodeNo2->m_Children+MaxAlphabetSize);
}
Esempio n. 9
0
bool operator<(const array<T, M>& left, const array<U, N>& right) {
  return lexicographical_compare(left.begin(), left.end(), right.begin(),
                                 right.end());
}
Esempio n. 10
0
 bool operator<(const MFace &f) const { return lexicographical_compare(v, v + 3, f.v, f.v + 3); }
Esempio n. 11
0
bool test2(input_iterator_wrapper<X>& x) {
    return lexicographical_compare(x, x, x, x, predicate);
}
Esempio n. 12
0
     inline bool lexicographical_compare(
     const Range1T& Arg1,
     const Range2T& Arg2)
 {
     return lexicographical_compare(Arg1, Arg2, is_less());
 }
Esempio n. 13
0
bool lexicographicalCompareString(string str1, string str2){
	return (lexicographical_compare(str1.c_str(), str1.c_str()+str1.length(), str2.c_str(), str2.c_str()+str2.length()));
};
Esempio n. 14
0
static void TestAlgorithms (void)
{
    static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 };
    const int* first = c_TestNumbers;
    const int* last = first + VectorSize(c_TestNumbers);
    intvec_t v, buf;
    v.assign (first, last);
    PrintVector (v);

    cout << "swap(1,2)\n";
    swap (v[0], v[1]);
    PrintVector (v);
    v.assign (first, last);

    cout << "copy(0,8,9)\n";
    copy (v.begin(), v.begin() + 8, v.begin() + 9);
    PrintVector (v);
    v.assign (first, last);

    cout << "copy with back_inserter\n";
    v.clear();
    copy (first, last, back_inserter(v));
    PrintVector (v);
    v.assign (first, last);

    cout << "copy with inserter\n";
    v.clear();
    copy (first, first + 5, inserter(v, v.begin()));
    copy (first, first + 5, inserter(v, v.begin() + 3));
    PrintVector (v);
    v.assign (first, last);

    cout << "copy_n(0,8,9)\n";
    copy_n (v.begin(), 8, v.begin() + 9);
    PrintVector (v);
    v.assign (first, last);

    cout << "copy_if(is_even)\n";
    intvec_t v_even;
    copy_if (v, back_inserter(v_even), &is_even);
    PrintVector (v_even);
    v.assign (first, last);

    cout << "for_each(printint)\n{ ";
    for_each (v, &printint);
    cout << "}\n";

    cout << "for_each(reverse_iterator, printint)\n{ ";
    for_each (v.rbegin(), v.rend(), &printint);
    cout << "}\n";

    cout << "find(10)\n";
    cout.format ("10 found at offset %zd\n", abs_distance (v.begin(), find (v, 10)));

    cout << "count(13)\n";
    cout.format ("%zu values of 13, %zu values of 18\n", count(v,13), count(v,18));

    cout << "transform(sqr)\n";
    transform (v, &sqr);
    PrintVector (v);
    v.assign (first, last);

    cout << "replace(13,666)\n";
    replace (v, 13, 666);
    PrintVector (v);
    v.assign (first, last);

    cout << "fill(13)\n";
    fill (v, 13);
    PrintVector (v);
    v.assign (first, last);

    cout << "fill_n(5, 13)\n";
    fill_n (v.begin(), 5, 13);
    PrintVector (v);
    v.assign (first, last);

    cout << "fill 64083 uint8_t(0x41) ";
    TestBigFill<uint8_t> (64083, 0x41);
    cout << "fill 64083 uint16_t(0x4142) ";
    TestBigFill<uint16_t> (64083, 0x4142);
    cout << "fill 64083 uint32_t(0x41424344) ";
    TestBigFill<uint32_t> (64083, 0x41424344);
    cout << "fill 64083 float(0.4242) ";
    TestBigFill<float> (64083, 0x4242f);
#if HAVE_INT64_T
    cout << "fill 64083 uint64_t(0x4142434445464748) ";
    TestBigFill<uint64_t> (64083, UINT64_C(0x4142434445464748));
#else
    cout << "No 64bit types available on this platform\n";
#endif

    cout << "copy 64083 uint8_t(0x41) ";
    TestBigCopy<uint8_t> (64083, 0x41);
    cout << "copy 64083 uint16_t(0x4142) ";
    TestBigCopy<uint16_t> (64083, 0x4142);
    cout << "copy 64083 uint32_t(0x41424344) ";
    TestBigCopy<uint32_t> (64083, 0x41424344);
    cout << "copy 64083 float(0.4242) ";
    TestBigCopy<float> (64083, 0.4242f);
#if HAVE_INT64_T
    cout << "copy 64083 uint64_t(0x4142434445464748) ";
    TestBigCopy<uint64_t> (64083, UINT64_C(0x4142434445464748));
#else
    cout << "No 64bit types available on this platform\n";
#endif

    cout << "generate(genint)\n";
    generate (v, &genint);
    PrintVector (v);
    v.assign (first, last);

    cout << "rotate(4)\n";
    rotate (v, 7);
    rotate (v, -3);
    PrintVector (v);
    v.assign (first, last);

    cout << "merge with (3,5,10,11,11,14)\n";
    const int c_MergeWith[] = { 3,5,10,11,11,14 };
    intvec_t vmerged;
    merge (v.begin(), v.end(), VectorRange(c_MergeWith), back_inserter(vmerged));
    PrintVector (vmerged);
    v.assign (first, last);

    cout << "inplace_merge with (3,5,10,11,11,14)\n";
    v.insert (v.end(), VectorRange(c_MergeWith));
    inplace_merge (v.begin(), v.end() - VectorSize(c_MergeWith), v.end());
    PrintVector (v);
    v.assign (first, last);

    cout << "remove(13)\n";
    remove (v, 13);
    PrintVector (v);
    v.assign (first, last);

    cout << "remove (elements 3, 4, 6, 15, and 45)\n";
    vector<uoff_t> toRemove;
    toRemove.push_back (3);
    toRemove.push_back (4);
    toRemove.push_back (6);
    toRemove.push_back (15);
    toRemove.push_back (45);
    typedef index_iterate<intvec_t::iterator, vector<uoff_t>::iterator> riiter_t;
    riiter_t rfirst = index_iterator (v.begin(), toRemove.begin());
    riiter_t rlast = index_iterator (v.begin(), toRemove.end());
    remove (v, rfirst, rlast);
    PrintVector (v);
    v.assign (first, last);

    cout << "unique\n";
    unique (v);
    PrintVector (v);
    v.assign (first, last);

    cout << "reverse\n";
    reverse (v);
    PrintVector (v);
    v.assign (first, last);

    cout << "lower_bound(10)\n";
    PrintVector (v);
    cout.format ("10 begins at position %zd\n", abs_distance (v.begin(), lower_bound (v, 10)));
    v.assign (first, last);

    cout << "upper_bound(10)\n";
    PrintVector (v);
    cout.format ("10 ends at position %zd\n", abs_distance (v.begin(), upper_bound (v, 10)));
    v.assign (first, last);

    cout << "equal_range(10)\n";
    PrintVector (v);
    TestEqualRange (v);
    v.assign (first, last);

    cout << "sort\n";
    reverse (v);
    PrintVector (v);
    random_shuffle (v);
    sort (v);
    PrintVector (v);
    v.assign (first, last);

    cout << "stable_sort\n";
    reverse (v);
    PrintVector (v);
    random_shuffle (v);
    stable_sort (v);
    PrintVector (v);
    v.assign (first, last);

    cout << "is_sorted\n";
    random_shuffle (v);
    const bool bNotSorted = is_sorted (v.begin(), v.end());
    sort (v);
    const bool bSorted = is_sorted (v.begin(), v.end());
    cout << "unsorted=" << bNotSorted << ", sorted=" << bSorted << endl;
    v.assign (first, last);

    cout << "find_first_of\n";
    static const int c_FFO[] = { 10000, -34, 14, 27 };
    cout.format ("found 14 at position %zd\n", abs_distance (v.begin(), find_first_of (v.begin(), v.end(), VectorRange(c_FFO))));
    v.assign (first, last);

    static const int LC1[] = { 3, 1, 4, 1, 5, 9, 3 };
    static const int LC2[] = { 3, 1, 4, 2, 8, 5, 7 };
    static const int LC3[] = { 1, 2, 3, 4 };
    static const int LC4[] = { 1, 2, 3, 4, 5 };
    cout << "lexicographical_compare";
    cout << "\nLC1 < LC2 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC2));
    cout << "\nLC2 < LC2 == " << lexicographical_compare (VectorRange(LC2), VectorRange(LC2));
    cout << "\nLC3 < LC4 == " << lexicographical_compare (VectorRange(LC3), VectorRange(LC4));
    cout << "\nLC4 < LC1 == " << lexicographical_compare (VectorRange(LC4), VectorRange(LC1));
    cout << "\nLC1 < LC4 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC4));

    cout << "\nmax_element\n";
    cout.format ("max element is %d\n", *max_element (v.begin(), v.end()));
    v.assign (first, last);

    cout << "min_element\n";
    cout.format ("min element is %d\n", *min_element (v.begin(), v.end()));
    v.assign (first, last);

    cout << "partial_sort\n";
    reverse (v);
    partial_sort (v.begin(), v.iat(v.size() / 2), v.end());
    PrintVector (v);
    v.assign (first, last);

    cout << "partial_sort_copy\n";
    reverse (v);
    buf.resize (v.size());
    partial_sort_copy (v.begin(), v.end(), buf.begin(), buf.end());
    PrintVector (buf);
    v.assign (first, last);

    cout << "partition\n";
    partition (v.begin(), v.end(), &is_even);
    PrintVector (v);
    v.assign (first, last);

    cout << "stable_partition\n";
    stable_partition (v.begin(), v.end(), &is_even);
    PrintVector (v);
    v.assign (first, last);

    cout << "next_permutation\n";
    buf.resize (3);
    iota (buf.begin(), buf.end(), 1);
    PrintVector (buf);
    while (next_permutation (buf.begin(), buf.end()))
	PrintVector (buf);
    cout << "prev_permutation\n";
    reverse (buf);
    PrintVector (buf);
    while (prev_permutation (buf.begin(), buf.end()))
	PrintVector (buf);
    v.assign (first, last);

    cout << "reverse_copy\n";
    buf.resize (v.size());
    reverse_copy (v.begin(), v.end(), buf.begin());
    PrintVector (buf);
    v.assign (first, last);

    cout << "rotate_copy\n";
    buf.resize (v.size());
    rotate_copy (v.begin(), v.iat (v.size() / 3), v.end(), buf.begin());
    PrintVector (buf);
    v.assign (first, last);

    static const int c_Search1[] = { 5, 6, 7, 8, 9 }, c_Search2[] = { 10, 10, 11, 14 };
    cout << "search\n";
    cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search1))));
    cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search2))));
    cout << "find_end\n";
    cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search1))));
    cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search2))));
    cout << "search_n\n";
    cout.format ("{14} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 1, 14)));
    cout.format ("{13,13} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 2, 13)));
    cout.format ("{10,10,10} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 3, 10)));
    v.assign (first, last);

    cout << "includes\n";
    static const int c_Includes[] = { 5, 14, 15, 18, 20 };
    cout << "includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes)-1);
    cout << ", not includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes));
    cout << endl;

    static const int c_Set1[] = { 1, 2, 3, 4, 5, 6 }, c_Set2[] = { 4, 4, 6, 7, 8 };
    intvec_t::iterator setEnd;
    cout << "set_difference\n";
    v.resize (4);
    setEnd = set_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
    PrintVector (v);
    assert (setEnd == v.end());
    cout << "set_symmetric_difference\n";
    v.resize (7);
    setEnd = set_symmetric_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
    PrintVector (v);
    assert (setEnd == v.end());
    cout << "set_intersection\n";
    v.resize (2);
    setEnd = set_intersection (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
    PrintVector (v);
    assert (setEnd == v.end());
    cout << "set_union\n";
    v.resize (9);
    setEnd = set_union (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
    PrintVector (v);
    assert (setEnd == v.end());
    v.assign (first, last);
}
constexpr bool operator<(array<T, N> const & x, array<T, N> const & y)
{
 return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
}
Esempio n. 16
0
 bool operator()(const vector<string> *lhs, const vector<string> *rhs) const {
   return lexicographical_compare(lhs->cbegin(), lhs->cend(),
       rhs->cbegin(), rhs->cend());
 }
Esempio n. 17
0
bool LexComparator::operator()(const std::list<AspFluent>& a, const std::list<AspFluent> &b) const {
  return lexicographical_compare(a.begin(),a.end(),b.begin(),b.end(),ActionComparator());
}
Esempio n. 18
0
bool _VectorBase::operator<(const _VectorBase& __other_vector) const
{
    STL_ASSERT((_M_get_finish() >= _M_get_start()) && (__other_vector._M_get_finish() >= __other_vector._M_get_start()));
    return lexicographical_compare(_M_get_start(), _M_get_finish(), __other_vector._M_get_start(), __other_vector._M_get_finish());
}