My portable distribution of Code::Blocks

This commit is contained in:
Михаил Агарков 2024-07-04 19:52:56 +03:00
commit 40a4ca5172
20205 changed files with 6747731 additions and 0 deletions

BIN
Addr2LineUI.exe Normal file

Binary file not shown.

View file

@ -0,0 +1,12 @@
MouseDragScrollEnabled=1
MouseEditorFocusEnabled=0
MouseFocusEnabled=0
MouseDragDirection=0
MouseDragKey=0
MouseDragSensitivity=5
MouseToLineRatio=30
MouseContextDelay=10
MouseWheelZoom=0
PropagateLogZoomSize=0
MouseHtmlFontSize=0
MouseWheelZoomReverse=0

View file

@ -0,0 +1,11 @@
ExternalEditor=
SnippetFile=D:\\AppData\\CodeBlocks\\codesnippets.xml
SnippetFolder=
ViewSearchBox=1
casesensitive=1
scope=2
EditorsStayOnTop=1
ToolTipsOption=1
ExternalPersistentOpen=0
WindowState=
WindowPosition=200 150 300 400

View file

@ -0,0 +1,7 @@
BrowseMarksEnabled=0
BrowseMarksStyle=1
BrowseMarksToggleKey=0
LeftMouseDelay=200
BrowseMarksClearAllMethod=0
WrapJumpEntries=0
ShowToolbar=0

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

BIN
Borland/BCC55/Bin/bcc32.exe Normal file

Binary file not shown.

BIN
Borland/BCC55/Bin/brc32.exe Normal file

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,36 @@
#
# Inprise C++Builder - (C) Copyright 1999 by Borland International
#
CC = bcc32
RC = brcc32
AS = tasm32
!if $d(__NMAKE__)
CXX = bcc32 -P
CPP = bcc32 -P
!endif
.asm.obj:
$(AS) $(AFLAGS) $&.asm
.c.exe:
$(CC) $(CFLAGS) $&.c
.c.obj:
$(CC) $(CFLAGS) /c $&.c
.cpp.exe:
$(CC) $(CFLAGS) $&.cpp
.cpp.obj:
$(CC) $(CPPFLAGS) /c $&.cpp
.rc.res:
$(RC) $(RFLAGS) /r $&
.SUFFIXES: .exe .obj .asm .c .res .rc
!if !$d(BCEXAMPLEDIR)
BCEXAMPLEDIR = $(MAKEDIR)\..\EXAMPLES
!endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Borland/BCC55/Bin/cpp32.exe Normal file

Binary file not shown.

Binary file not shown.

BIN
Borland/BCC55/Bin/grep.exe Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Borland/BCC55/Bin/make.exe Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Borland/BCC55/Bin/tdump.exe Normal file

Binary file not shown.

BIN
Borland/BCC55/Bin/tlib.exe Normal file

Binary file not shown.

BIN
Borland/BCC55/Bin/touch.exe Normal file

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,86 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* accum.cpp - Example program for accumulate. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <compnent.h>
#include <numeric> // For accumulate.
#include <vector> // For vector.
#include <functional> // For multiplies.
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Typedef for vector iterators.
//
typedef vector<int,allocator<int> >::iterator iterator;
//
// Initialize a vector using an array of integers.
//
int d1[10] = {1,2,3,4,5,6,7,8,9,10};
vector<int,allocator<int> > v1(d1+0, d1+10);
//
// Accumulate sums and products.
//
int sum = accumulate(v1.begin(), v1.end(), 0);
int prod = accumulate(v1.begin(), v1.end(), 1, multiplies<int>());
//
// Output the results.
//
cout << "For the series: ";
for(iterator i = v1.begin(); i != v1.end(); i++)
cout << *i << " ";
cout << " where N = 10." << endl;
cout << "The sum = (N*N + N)/2 = " << sum << endl;
cout << "The product = N! = " << prod << endl;
return 0;
}

View file

@ -0,0 +1,91 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* adj_diff.cpp - Example program for adjacent_difference.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <numeric> // For adjacent_difference.
#include <vector> // For vector.
#include <functional> // For multiplies.
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Initialize a vector of ints from an array.
//
int arr[10] = {1,1,2,3,5,8,13,21,34,55};
vector<int,allocator<int> > v(arr+0, arr+10);
//
// Two uninitialized vectors for storing results.
//
vector<int,allocator<int> > diffs(10), prods(10);
//
// Calculate difference(s) using default operator (minus).
//
adjacent_difference(v.begin(),v.end(),diffs.begin());
//
// Calculate difference(s) using the times operator.
//
adjacent_difference(v.begin(), v.end(), prods.begin(), multiplies<int>());
//
// Output the results.
//
cout << "For the vector: " << endl << " ";
copy(v.begin(),v.end(),ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << endl;
cout << "The differences between adjacent elements are: " << endl << " ";
copy(diffs.begin(),diffs.end(), ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << endl;
cout << "The products of adjacent elements are: " << endl << " ";
copy(prods.begin(),prods.end(), ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl;
return 0;
}

View file

@ -0,0 +1,80 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* advance.cpp - Example program for advancing iterators.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iterator>
#include <list>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Initialize a list using an array.
//
int arr[6] = {3,4,5,6,7,8};
list<int,allocator<int> > l(arr+0, arr+6);
//
// Declare a list iterator, s.b. a ForwardIterator.
//
list<int,allocator<int> >::iterator itr = l.begin();
//
// Output the original list.
//
cout << "For the list: ";
copy(l.begin(),l.end(),ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << endl;
cout << "When the iterator is initialized to l.begin(),"
<< endl << "it points to " << *itr << endl << endl;
//
// operator+ is not available for a ForwardIterator, so use advance.
//
advance(itr, 4);
cout << "After advance(itr,4), the iterator points to " << *itr << endl;
return 0;
}

View file

@ -0,0 +1,229 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg1.cpp - Example program for STL generic algorithms that initialize
* sequences. Section 12.2
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <list>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <string.h>
#include <iostream>
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
class iotaGen
{
public:
iotaGen (int iv) : current(iv) { }
int operator () () { return current++; }
private:
int current;
};
//
// Illustrate the use of the fill and fill_n functions.
//
void fill_example ()
{
cout << "Illustrate fill function" << endl;
//
// Example 1, fill an array with initial values
//
char buffer[100], *bufferp = buffer;
fill (bufferp,(bufferp + 100),'\0');
fill_n (bufferp, 10, 'x');
cout << buffer << endl;
//
// Example 2, use fill to initialize a list.
//
list<string,allocator<string> > aList;
fill_n (inserter(aList, aList.begin()), 10, "empty");
copy(aList.begin(), aList.end(), ostream_iterator<string,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Example 3, use fill to overwrite values in a list.
//
fill (aList.begin(), aList.end(), "full");
copy(aList.begin(), aList.end(), ostream_iterator<string,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Example 4, fill in a portion of a list.
//
vector<int,allocator<int> > iVec(10);
generate (iVec.begin(), iVec.end(), iotaGen(1));
vector<int,allocator<int> >::iterator seven = find(iVec.begin(), iVec.end(), 7);
#ifndef _RWSTD_FILL_NAME_CLASH
fill(iVec.begin(), seven, 0);
#else
std_fill(iVec.begin(), seven, 0);
#endif
copy(iVec.begin(), iVec.end(), ostream_iterator<int,char,char_traits<char> >(cout));
cout << endl;
}
//
// Illustrate the use of the copy function.
//
void copy_example ()
{
cout << "Illustrate copy function " << endl;
//
// Example 1, a simple copy.
//
char * source = "reprise";
char * surpass = "surpass";
char buffer[120], *bufferp = buffer;
copy(source, source + strlen(source) + 1, bufferp);
//
// Example 2, self copies.
//
*copy(bufferp + 2, bufferp+ strlen(buffer), bufferp) = '\0';
int buflen = strlen(buffer) + 1;
copy_backward(bufferp, bufferp + buflen, bufferp + buflen + 3);
copy(surpass, surpass + 3, bufferp);
//
// Example 3, copy to output.
//
copy(bufferp, bufferp + strlen(buffer), ostream_iterator<char,char,char_traits<char> >(cout));
cout << endl;
//
// Example 4, use copy to convert type.
//
list<char,allocator<char> > char_list;
copy(bufferp, bufferp + strlen(buffer),
inserter(char_list,char_list.end()));
char * big = "big ";
copy(big, big + 4, inserter(char_list, char_list.begin()));
char buffer2[200], *buffer2p = buffer2;
*copy(char_list.begin(), char_list.end(), buffer2p) = '\0';
cout << buffer2 << endl;
}
#include <sstream>
string generateLabel ()
{
//
// Generate a label string of the form L_ddd.
//
static int lastLabel = 0;
ostringstream ost;
ost << "L_" << lastLabel++ << '\0';
return ost.str();
}
//
// Illustrate the use of the generate and genrate_n functions.
//
void generate_example ()
{
cout << "Illustrate generate algorithm" << endl;
//
// Example 1, generate a list of label numbers.
//
list<string,allocator<string> > labelList;
generate_n (inserter(labelList, labelList.begin()), 4, generateLabel);
copy(labelList.begin(),labelList.end(),ostream_iterator<string,char,char_traits<char> >(cout," "));
cout << endl;
//
// Example 2, generate an arithmetic progression.
//
vector<int,allocator<int> > iVec(10);
generate (iVec.begin(), iVec.end(), iotaGen(2));
generate_n (iVec.begin(), 5, iotaGen(7));
copy (iVec.begin(), iVec.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
//
// Illustrate the use of the algorithm swap_ranges.
//
void swap_example ()
{
cout << "Illustrate swap_ranges algorithm" << endl;
//
// First make two parallel sequences.
//
int data[] = {12, 27, 14, 64}, *datap = data;
vector<int,allocator<int> > aVec(4);
generate (aVec.begin(), aVec.end(), iotaGen(1));
//
// Illustrate swap and swap_itr.
//
swap(data[0], data[2]);
copy (data, data+4, ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
vector<int,allocator<int> >::iterator last = aVec.end(); last--;
iter_swap(aVec.begin(), last);
copy (aVec.begin(), aVec.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Now swap the entire sequence.
//
swap_ranges (aVec.begin(), aVec.end(), datap);
copy (data, data+4, ostream_iterator<int,char,char_traits<char> >(cout, " ")), cout << endl;
copy (aVec.begin(), aVec.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
int main ()
{
cout << "STL generic algorithms -- initialization algorithms" << endl;
fill_example();
copy_example();
generate_example();
swap_example();
cout << "End of initialization tests" << endl;
return 0;
}

View file

@ -0,0 +1,249 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg2.cpp - test program for STL generic algorithm that search for
* elements that satisfy a condition. Section 12.3
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <list>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <string.h>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int randomInteger (int m) { return rand() % m; }
bool isLeapYear (unsigned int year)
{
if (year % 1000 == 0)
return true;
if (year % 100 == 0)
return false;
if (year % 4 == 0)
return true;
return false;
}
void split (const string & text, const string & separators,
list<string,allocator<string> > & words)
{
int n = text.length();
int start = text.find_first_not_of(separators);
while ((start >= 0) && (start < n))
{
int stop = text.find_first_of(separators, start);
if ((stop < 0) || (stop > n)) stop = n;
words.push_back (text.substr(start, stop-start));
start = text.find_first_not_of(separators, stop+1);
}
}
//
// Illustrate use of the find function.
//
void find_test ()
{
cout << "Test of algorithm find" << endl;
int vintageYears[] = { 1967, 1972, 1974, 1980, 1995 };
vector<int,allocator<int> >::iterator start = vintageYears;
vector<int,allocator<int> >::iterator stop = vintageYears + 5;
vector<int,allocator<int> >::iterator where = find_if(start, stop, isLeapYear);
if (where != stop)
cout << "first vintage leap year is " << *where << endl;
else
cout << "no vintage leap years" << endl;
where = find(start, stop, 1995);
if (where != stop)
cout << "1995 is position " << where - start << " in sequence" << endl;
else
cout << "1995 does not occur in sequence" << endl;
}
void find_adjacent_test ()
{
cout << "Test of algorithm find adjacent" << endl;
char * text = "The bookkeeper carefully opened the door";
vector<char,allocator<char> >::iterator start = text;
vector<char,allocator<char> >::iterator stop = text + strlen(text);
vector<char,allocator<char> >::iterator where = start;
cout << "In the text " << text << endl;
while ((where = adjacent_find(where, stop)) != stop)
{
cout << "double " << *where << " in position " << where-start << endl;
++where;
}
}
//
// Illustrate the use of the search function.
//
void search_test ()
{
cout << "Test of algorithm search" << endl;
char * base = "aspirations";
char * text = "ration";
char * where = search(base, base+strlen(base), text, text+strlen(text));
if (*where != '\0')
cout << "substring begins in position " << where - base << endl;
else
cout << "substring does not occur in text" << endl;
}
//
// Illustrate use of max_element and min_element algorithms.
//
void max_min_example ()
{
cout << "Test of max and min algorithms " << endl;
//
// Make a vector of random numbers between 0 and 99.
//
vector<int,allocator<int> > numbers(25);
for (int i = 0; i < 25; i++)
numbers[i] = randomInteger(100);
//
// Print the maximum.
//
vector<int,allocator<int> >::iterator max = max_element(numbers.begin(), numbers.end());
cout << "largest value was " << *max << endl;
//
// Example using strings.
//
string text = "it was the best of times, it was the worst of times.";
list<string,allocator<string> >words;
split(text, " .,!:;", words);
cout << "The smallest word is "
<< * min_element(words.begin(), words.end())
<< " and the largest word is "
<< * max_element(words.begin(), words.end())
<< endl;
}
//
// Illustrate the use of the mismatch function.
//
void mismatch_test (char * a, char * b)
{
pair<char *, char *> differPositions(0, 0);
char * aDiffPos;
char * bDiffPos;
if (strlen(a) < strlen(b))
{
differPositions = mismatch(a, a + strlen(a), b);
aDiffPos = differPositions.first;
bDiffPos = differPositions.second;
}
else
{
differPositions = mismatch(b, b + strlen(b), a);
aDiffPos = differPositions.second;
bDiffPos = differPositions.first;
}
cout << "string " << a;
if (*aDiffPos == *bDiffPos)
cout << " is equal to ";
else if (*aDiffPos < *bDiffPos)
cout << " is less than ";
else
cout << " is greater than ";
cout << b << endl;
}
int main ()
{
cout << "STL generic algorithms -- Searching Algorithms" << endl;
find_test();
find_adjacent_test();
search_test();
max_min_example();
mismatch_test("goody", "goody");
mismatch_test("good", "goody");
mismatch_test("goody", "good");
mismatch_test("good", "fred");
mismatch_test("fred", "good");
cout << "End of search algorithms test program" << endl;
return 0;
}

View file

@ -0,0 +1,324 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg3.cpp - Sample programs for STL generic algorihtms that modify
* their arguments in place. Section 12.4
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <ctype.h>
#include <string>
#include <string.h>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
class iotaGenerator
{
public:
iotaGenerator (int iv) : current(iv) { }
int operator () () { return current++; }
private:
int current;
};
bool isEven (int n) { return 0 == (n % 2); }
//
// Illustrate the use of the reverse function.
//
void reverse_example ()
{
cout << "Illustrate reverse algorithm" << endl;
//
// Example 1, reversing a string.
//
char ctext[30] = "Rats live on no evil star";
char text[30];
strcpy(text,ctext);
reverse (text, text + strlen(text));
cout << text << endl;
//
// Example 2, reversing a list.
//
list<int,allocator<int> > iList;
generate_n(inserter(iList, iList.begin()), 10, iotaGenerator(2));
reverse (iList.begin(), iList.end());
copy (iList.begin(), iList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
//
// Illustrate the use of the replace function.
//
void replace_example ()
{
cout << "Illustrate replace algorithm" << endl;
//
// Make vector 0 1 2 3 4.
//
vector<int,allocator<int> > numbers(11);
for (int i = 0; i < 11; i++)
numbers[i] = i < 5 ? i : 10 - i;
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Replace 0 by 2.
//
replace (numbers.begin(), numbers.end(), 3, 7);
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Replace even numbers by 9.
//
replace_if (numbers.begin(), numbers.end(), isEven, 9);
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Copy into a list, replacing 9 by 3.
//
int aList[] = { 2, 1, 4, 3, 2, 5 };
int bList[6];
int cList[6];
replace_copy (aList, aList+6, &bList[0], 2, 7);
replace_copy_if (bList, bList+6, &cList[0], bind2nd(greater<int>(), 3), 8);
copy (bList, bList + 6, ostream_iterator<int,char,char_traits<char> >(cout, " ")); cout << endl;
copy (cList, cList + 6, ostream_iterator<int,char,char_traits<char> >(cout, " ")); cout << endl;
}
//
// Illustrate the use of the rotate function.
//
void rotate_example ()
{
cout << "Illustrate rotate algorithm" << endl;
//
// Create the list 1 2 3 ... 10
//
list<int,allocator<int> > iList;
generate_n(inserter(iList, iList.begin()), 10, iotaGenerator(1));
//
// Find the location of the seven.
//
list<int,allocator<int> >::iterator middle = find(iList.begin(), iList.end(), 7);
//
// Now rotate around that location.
//
rotate(iList.begin(), middle, iList.end());
copy (iList.begin(), iList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Rotate again around the same location.
//
list<int,allocator<int> > cList;
rotate_copy(iList.begin(), middle,iList.end(),
inserter(cList, cList.begin()));
copy (cList.begin(), cList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
//
// Illustrate the use of the paration function.
//
void partition_example ()
{
cout << "Illustrate partition algorithm" << endl;
//
// First make the vector 1 2 3 ... 10.
//
vector<int,allocator<int> > numbers(10);
generate(numbers.begin(), numbers.end(), iotaGenerator(1));
//
// Now put the odd values low, even values high.
//
vector<int,allocator<int> >::iterator result = partition(numbers.begin(),numbers.end(),
isEven);
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
cout << "middle location " << result - numbers.begin() << endl;
//
// Now do a stable partition.
//
generate(numbers.begin(), numbers.end(), iotaGenerator(1));
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
bool nameCompare (char * a, char * b) { return strcmp(a, b) <= 0; }
//
// Illustrate the use of the next_permutation function.
//
void permutation_example ()
{
//
// Start with the values 1 2 3 in sequence.
//
int start [] = {1, 2, 3 };
do
{
copy (start, start + 3, ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
while (next_permutation(start, start + 3));
char * names[] = { "Alpha", "Beta", "Gamma" };
do
{
copy (names, names + 3, ostream_iterator<char *,char,char_traits<char> >(cout, " "));
cout << endl;
}
while (next_permutation(names, names + 3, nameCompare));
char * cword = "bela";
char word[4];
strcpy(word,cword);
do
cout << word << ' ';
while (prev_permutation(word, &word[4]));
cout << endl;
}
//
// Illustrate the use of the inplace_merge function.
//
void inplace_merge_example ()
{
cout << "Illustrate inplace merge algorithm" << endl;
//
// First generate the numbers 0 2 4 6 8 1 3 5 7 9.
//
vector<int,allocator<int> > numbers(10);
for (int i = 0; i < 10; i++)
numbers[i] = i < 5 ? 2 * i : 2 * (i - 5) + 1;
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
vector<int,allocator<int> >::iterator midvec = find(numbers.begin(), numbers.end(), 1);
//
// Copy them into a list.
//
list<int,allocator<int> > numList;
copy(numbers.begin(), numbers.end(), inserter(numList, numList.begin()));
list<int,allocator<int> >::iterator midList = find(numList.begin(), numList.end(), 1);
copy (numList.begin(), numList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Now put them back together.
//
inplace_merge(numbers.begin(), midvec, numbers.end());
inplace_merge(numList.begin(), midList, numList.end());
copy (numList.begin(), numList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
struct RandomInteger
{
int operator() (int m) { return rand() % m; }
};
//
// Illustrate the use of the random_shuffle function.
//
void random_shuffle_example ()
{
//
// First make the vector 1 2 3 ... 10.
//
vector<int,allocator<int> > numbers(10);
generate(numbers.begin(), numbers.end(), iotaGenerator(1));
RandomInteger random;
//
// Randomly shuffle the elements.
//
random_shuffle(numbers.begin(), numbers.end(), random);
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Do it again.
//
random_shuffle(numbers.begin(), numbers.end(), random);
copy (numbers.begin(), numbers.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
int main ()
{
cout << "STL generic algorithms -- in-place algorithms" << endl;
reverse_example();
replace_example();
rotate_example();
partition_example();
permutation_example();
inplace_merge_example();
random_shuffle_example();
cout << "End of in-place algorithm sample program" << endl;
return 0;
}

View file

@ -0,0 +1,154 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg4.cpp - Example programs for STL generic algorithms removal
* algorithms. Section 12.5
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <list>
#include <set>
#include <algorithm>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
bool isEven (int n) { return 0 == (n % 2); }
//
// Illustrate the use of the remove algorithm.
//
void remove_example ()
{
cout << "Remove Algorithm examples" << endl;
//
// Create a list of numbers.
//
int data[] = { 1, 2, 4, 3, 1, 4, 2 };
list<int,allocator<int> > aList;
copy (data, data+7, inserter(aList, aList.begin()));
cout << "Original list: ";
copy (aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Remove 2's, copy into a new list.
//
list<int,allocator<int> > newList;
remove_copy (aList.begin(), aList.end(), back_inserter(newList), 2);
cout << "After removing 2's: ";
copy (newList.begin(), newList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Remove 2's in place.
//
list<int,allocator<int> >::iterator where;
where = remove(aList.begin(), aList.end(), 2);
cout << "List after removal, before erase: ";
copy (aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
aList.erase(where, aList.end());
cout << "List after erase: ";
copy (aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Remove all even values.
//
where = remove_if (aList.begin(), aList.end(), isEven);
aList.erase(where, aList.end());
cout << "List after removing even values: ";
copy (aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
//
// Illustrate use of the unqiue algorithm.
//
void unique_example ()
{
//
// First make a list of values.
//
int data[] = { 1, 3, 3, 2, 2, 4 };
list<int,allocator<int> > aList;
copy(data, data+6, inserter(aList, aList.begin()));
cout << "Origianal List: ";
copy(aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Copy unique elements into a set.
//
set<int, less<int>,allocator<int> > aSet;
// unique_copy(aList.begin(), aList.end(), inserter(aSet, aSet.begin()));
cout << "Set after unique_copy: ";
copy(aSet.begin(), aSet.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Copy unique elements in place.
//
list<int,allocator<int> >::iterator where;
where = unique(aList.begin(), aList.end());
cout << "List after calling unique: ";
copy(aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Remove trailing values.
//
aList.erase(where, aList.end());
cout << "List after erase: ";
copy(aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
int main ()
{
cout << "STL generic algorithms -- Removal Algorithms" << endl;
remove_example();
unique_example();
cout << "End of removal algorithms sample program" << endl;
return 0;
}

View file

@ -0,0 +1,207 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg5.cpp - Example programs for STL generic algorithms those producing
* scalar values. Section 12.6
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <string.h>
#include <string>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Forward declarations.
//
bool isVowel (char);
void count_example();
void accumulate_example();
template<class T>
list<T,allocator<void> > & listadd(list<T,allocator<void> > & base, T & newValue);
void inner_product_example();
void equal_example();
bool isVowel (char c)
{
switch (c)
{
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return true;
}
return false;
}
//
// Illustrate the use of the count function.
//
void count_example ()
{
int ecount = 0;
int vowelCount = 0;
char * text = "Now is the time to begin";
count (text, text + strlen(text), 'e', ecount);
count_if (text, text + strlen(text), isVowel, vowelCount);
cout << "There are " << ecount << " letter e's " << endl << "and "
<< vowelCount << " vowels in the text:" << text << endl;
}
//
// Add n to 1 to list.
//
list<int,allocator<int> >& intReplicate (list<int,allocator<int> >& nums, int n)
{
while (n) nums.push_back(n--);
return nums;
}
//
// Illustrate the use of the accumulate function.
//
void accumulate_example ()
{
int numbers[] = { 1, 2, 3, 4, 5 };
int sum = accumulate(numbers, numbers+5, 0);
int product = accumulate(numbers, numbers+5, 1, multiplies<int>());
cout << "The sum of the first five numbers is " << sum << endl;
cout << "The product of the first five numbers is " << product << endl;
//
// Example with different types for init.
//
list<int,allocator<int> > nums;
nums = accumulate(numbers, numbers+5, nums, intReplicate);
copy (nums.begin(), nums.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
//
// Illustrate the use of the inner_product function.
//
void inner_product_example ()
{
int a[] = { 4, 3, -2 };
int b[] = { 7, 3, 2 };
//
// Example 1, simple inner product.
//
int in1 = inner_product(a, a+3, b, 0);
cout << "Inner product is " << in1 << endl;
//
// Example 2, using different operations.
//
bool anyequal = inner_product(a, a+3, b, true, logical_or<bool>(),
equal_to<int>());
cout << "any equal? " << anyequal << endl;
}
//
// Illustrate the use of the equal function.
//
void equal_example ()
{
int a[] = { 4, 5, 3 };
int b[] = { 4, 3, 3 };
int c[] = { 4, 5, 3 };
cout << "a = b is:" << equal(a, a+3, b) << endl;
cout << "a = c is:" << equal(a, a+3, c) << endl;
cout << "a pair-wise-greater_equal b is"
<< equal(a, a+3, b, greater_equal<int>()) << endl;
}
//
// Illustrate the use of the lexical_comparison function.
//
void lexical_comparison_example ()
{
char * wordOne = "everything";
char * wordTwo = "everybody";
cout << "compare everybody to everything "
<< lexicographical_compare(wordTwo, wordTwo+strlen(wordTwo), wordOne,
wordOne+strlen(wordOne))
<< endl;
int a[] = { 3, 4, 5, 2 };
int b[] = { 3, 4, 5 };
int c[] = { 3, 5 };
cout << "compare a to b: " << lexicographical_compare(a,a+4,b,b+3) << endl;
cout << "compare a to c: " << lexicographical_compare(a,a+4,c,c+2) << endl;
}
int main ()
{
cout << "STL generic algorithms -- algorithms that produce scalar results" << endl;
count_example();
accumulate_example();
inner_product_example();
equal_example();
lexical_comparison_example();
cout << "End of scalar algorithms test" << endl;
return 0;
}

View file

@ -0,0 +1,186 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg6.cpp - STL generic algorithms that produce new sequences
* section 12.7
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int square (int n) { return n * n; }
class iotaGen
{
public:
iotaGen (int iv) : current(iv) { }
int operator () () { return current++; }
private:
int current;
};
//
// Illustrate the use of the transform algorithm.
//
void transform_example ()
{
//
// Generate a list of values from 1 to 6.
//
list<int,allocator<int> > aList;
generate_n (inserter(aList, aList.begin()), 6, iotaGen(1));
cout << "Original list: ";
copy(aList.begin(), aList.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Transform elements by squaring, copy into vector.
//
vector<int,allocator<int> > aVec(6);
transform (aList.begin(), aList.end(), aVec.begin(), square);
cout << "After squaring: ";
copy(aVec.begin(), aVec.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Transform vector again, in place, yielding 4th powers.
//
transform (aVec.begin(), aVec.end(), aVec.begin(), square);
cout << "After squaring again: ";
copy(aVec.begin(), aVec.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Transform in parallel, yielding cubes.
//
vector<int,allocator<int> > cubes(6);
transform (aVec.begin(), aVec.end(), aList.begin(), cubes.begin(),
divides<int>());
cout << "After division: ";
copy(cubes.begin(), cubes.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
//
// Illustrate the use of the partial sum algorithm.
//
void partial_sum_example ()
{
//
// Generate values 1 to 5.
//
vector<int,allocator<int> > aVec(5);
generate (aVec.begin(), aVec.end(), iotaGen(1));
//
// Output partial sums.
//
cout << "Partial sums examples" << endl;
cout << "Partial sums : ";
partial_sum (aVec.begin(), aVec.end(), ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Output partial products.
//
cout << "Partial products: ";
partial_sum (aVec.begin(), aVec.end(),
ostream_iterator<int,char,char_traits<char> >(cout, " "),
multiplies<int>() );
cout << endl;
}
//
// Illustrate the use of the adjacent difference algorithm.
//
void adjacent_difference_example ()
{
//
// Generate values 1 to 5.
//
vector<int,allocator<int> > aVec(5);
generate (aVec.begin(), aVec.end(), iotaGen(1));
//
// Output partial sums.
//
cout << "Adjacent Differences examples" << endl;
cout << "Adjacent Differences : ";
adjacent_difference (aVec.begin(), aVec.end(),
ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
//
// Output partial products.
//
cout << "Adjacent sums: ";
adjacent_difference (aVec.begin(), aVec.end(),
ostream_iterator<int,char,char_traits<char> >(cout, " "), plus<int>());
cout << endl;
}
int main ()
{
cout << "STL generic algorithms -- that transform sequences" << endl;
transform_example();
partial_sum_example();
adjacent_difference_example ();
cout << "End generic transform algorithms example" << endl;
return 0;
}

View file

@ -0,0 +1,333 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* alg7.cpp - Illustrate the use of the sort related generic algorithms.
* Section 13
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int randomInteger (unsigned int n) { return rand() % n; }
int randomValue () { return randomInteger(100); }
ostream_iterator<int,char,char_traits<char> > intOut(cout, " ");
void sortExample ()
{
cout << "Sort algorithms" << endl;
//
// Fill both a vector and a deque with random integers.
//
vector<int,allocator<int> > aVec(15);
deque<int,allocator<int> > aDec(15);
generate (aVec.begin(), aVec.end(), randomValue);
generate (aDec.begin(), aDec.end(), randomValue);
//
// Sort the vector ascending.
//
sort (aVec.begin(), aVec.end());
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
//
// Sort the deque descending.
//
sort (aDec.begin(), aDec.end(), greater<int>() );
copy (aDec.begin(), aDec.end(), intOut);
cout << endl;
//
// Sort the vector descending?
//
sort (aVec.rbegin(), aVec.rend());
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
}
void partial_sort_example ()
{
cout << "Partial sort examples" << endl;
//
// Make a vector of 15 random integers.
//
vector<int,allocator<int> > aVec(15);
generate (aVec.begin(), aVec.end(), randomValue);
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
//
// Partial sort the first seven positions.
//
partial_sort (aVec.begin(), aVec.begin() + 7, aVec.end());
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
//
// Make a list of random integers.
//
list<int,allocator<int> > aList(15, 0);
generate (aList.begin(), aList.end(), randomValue);
copy (aList.begin(), aList.end(), intOut);
cout << endl;
//
// Sort only the first seven elements.
//
vector<int,allocator<int> > start(7);
partial_sort_copy (aList.begin(), aList.end(),
start.begin(), start.end(), greater<int>());
copy (start.begin(), start.end(), intOut);
cout << endl;
}
//
// Illustrate the use of the nth_largest function.
//
void nth_element_example ()
{
cout << "Nth largest example" << endl;
//
// Make a vector of random integers.
//
vector<int,allocator<int> > aVec(10);
generate (aVec.begin(), aVec.end(), randomValue);
//
// Now find the 5th largest.
//
vector<int,allocator<int> >::iterator nth = aVec.begin() + 4;
nth_element(aVec.begin(), nth, aVec.end());
cout << "fifth largest is " << *nth << " in" << endl;
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
}
//
// Illustrate the use of the binary search functions.
//
void binary_search_example ()
{
cout << "Binary search example" << endl;
//
// Make an ordered vector of 15 random integers.
//
vector<int,allocator<int> > aVec(15);
generate (aVec.begin(), aVec.end(), randomValue);
sort (aVec.begin(), aVec.end());
copy (aVec.begin(), aVec.end(), intOut), cout << endl;
//
// See if it contains an eleven.
//
if (binary_search(aVec.begin(), aVec.end(), 11))
cout << "contains an 11" << endl;
else
cout << "does not contain an 11" << endl;
//
// Insert an 11 and a 14.
//
vector<int,allocator<int> >::iterator where;
where = lower_bound (aVec.begin(), aVec.end(), 11);
aVec.insert (where, 11);
where = upper_bound (aVec.begin(), aVec.end(), 14);
aVec.insert (where, 14);
copy (aVec.begin(), aVec.end(), intOut), cout << endl;
}
//
// Illustrate the use of the merge function.
//
void merge_example ()
{
cout << "Merge algorithm examples" << endl;
//
// Make a list and vector of 10 random integers.
//
vector<int,allocator<int> > aVec(10);
list<int,allocator<int> > aList(10, 0);
generate (aVec.begin(), aVec.end(), randomValue);
sort (aVec.begin(), aVec.end());
generate_n (aList.begin(), 10, randomValue);
aList.sort();
//
// Merge into a vector.
//
vector<int,allocator<int> > vResult (aVec.size() + aList.size());
merge (aVec.begin(), aVec.end(), aList.begin(), aList.end(),
vResult.begin());
//
// Merge into a list.
//
list<int,allocator<int> > lResult;
merge (aVec.begin(), aVec.end(), aList.begin(), aList.end(),
inserter(lResult, lResult.begin()));
//
// Merge into the output.
//
merge (aVec.begin(), aVec.end(), aList.begin(), aList.end(),
ostream_iterator<int,char,char_traits<char> >(cout, " "));
cout << endl;
}
class iotaGen
{
public:
iotaGen (int c = 0) : current(c) { }
int operator () () { return current++; }
private:
int current;
};
//
// Illustrate the use of the generic set functions.
//
void set_example ()
{
cout << "Set operations:" << endl;
//
// Make a couple of ordered lists.
//
list <int,allocator<int> > listOne, listTwo;
generate_n (inserter(listOne, listOne.begin()), 5, iotaGen(1));
generate_n (inserter(listTwo, listTwo.begin()), 5, iotaGen(3));
//
// union - 1 2 3 4 5 6 7
//
set_union (listOne.begin(), listOne.end(),
listTwo.begin(), listTwo.end(), intOut);
cout << endl;
//
// merge - 1 2 3 3 4 4 5 5 6 7
//
merge (listOne.begin(), listOne.end(),
listTwo.begin(), listTwo.end(), intOut);
cout << endl;
//
// intersection 3 4 5
//
set_intersection (listOne.begin(), listOne.end(),
listTwo.begin(), listTwo.end(), intOut);
cout << endl;
//
// difference 1 2
//
set_difference (listOne.begin(), listOne.end(),
listTwo.begin(), listTwo.end(), intOut);
cout << endl;
//
// symmetric difference 1 2 6 7
//
set_symmetric_difference (listOne.begin(), listOne.end(),
listTwo.begin(), listTwo.end(), intOut);
cout << endl;
if (includes(listOne.begin(), listOne.end(),
listTwo.begin(), listTwo.end()))
cout << "set is subset" << endl;
else
cout << "set is not subset" << endl;
}
//
// Illustrate the use of the heap functions.
//
void heap_example ()
{
ostream_iterator<int,char,char_traits<char> > intOut(cout, " ");
//
// Make a heap of 15 random integers.
//
vector<int,allocator<int> > aVec(15);
generate (aVec.begin(), aVec.end(), randomValue);
make_heap (aVec.begin(), aVec.end());
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
cout << "Largest value " << aVec.front() << endl;
//
// Remove largest and reheap.
//
pop_heap(aVec.begin(), aVec.end());
aVec.pop_back();
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
//
// Add a 97 to the heap.
//
aVec.push_back(97);
push_heap (aVec.begin(), aVec.end());
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
//
// Finally, make into sorted collection.
//
sort_heap (aVec.begin(), aVec.end());
copy (aVec.begin(), aVec.end(), intOut);
cout << endl;
}
int main ()
{
cout << "Sorting generic algorithms examples" << endl;
sortExample();
partial_sort_example();
nth_element_example();
binary_search_example();
merge_example();
set_example();
heap_example();
cout << "End sorting examples" << endl;
return 0;
}

View file

@ -0,0 +1,82 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* auto_ptr.cpp - Example program of auto_ptr. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <memory>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
//
// A simple structure.
//
struct X
{
X (int i = 0) : m_i(i) { }
int get() const { return m_i; }
int m_i;
};
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// b will hold a pointer to an X.
//
auto_ptr<X> b(new X(12345));
//
// a will now be the owner of the underlying pointer.
//
auto_ptr<X> a = b;
//
// Output the value contained by the underlying pointer.
//
cout << a->get() << endl;
//
// The pointer will be delete'd when a is destroyed on leaving scope.
//
return 0;
}

View file

@ -0,0 +1,82 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* b_search.cpp - Example program of binary search.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[10] = {0,1,2,2,3,4,2,2,6,7};
//
// Set up a vector.
//
vector<int,allocator<int> > v1(d1+0, d1+10);
sort(v1.begin(),v1.end());
//
// Try binary_search variants.
//
bool b1 = binary_search(v1.begin(),v1.end(),3);
bool b2 = binary_search(v1.begin(),v1.end(),11,less<int>());
//
// Output results.
//
cout << "In the vector: ";
copy(v1.begin(),v1.end(), ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << "The number 3 was "
<< (b1 ? "FOUND" : "NOT FOUND");
cout << endl << "The number 11 was "
<< (b2 ? "FOUND" : "NOT FOUND") << endl;
return 0;
}

View file

@ -0,0 +1,89 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* binders.cpp - Example program for binder1st & binder2nd.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <functional>
#include <algorithm>
#include <vector>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[4] = {1,2,3,4};
//
// Set up a vector.
//
vector<int,allocator<int> > v1(d1+0, d1+4);
//
// Create an 'equal to 3' unary predicate by binding 3 to
// the equal_to binary predicate.
//
binder1st<equal_to<int> > equal_to_3 = bind1st(equal_to<int>(),3);
//
// Now use this new predicate in a call to find_if.
//
iterator it1 = find_if(v1.begin(),v1.end(),equal_to_3);
//
// Even better, construct the new predicate on the fly.
//
iterator it2 = find_if(v1.begin(),v1.end(),bind1st(equal_to<int>(),3));
//
// And now the same thing using bind2nd.
// Same result since == is commutative.
//
iterator it3 = find_if(v1.begin(),v1.end(),bind2nd(equal_to<int>(),3));
//
// Output results.
//
cout << *it1 << " " << *it2 << " " << *it3 << endl;
return 0;
}

View file

@ -0,0 +1,61 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* bitset.cpp - Example program for bitset. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <bitset>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
bitset<8> b;
b |= 5;
#ifndef _RWSTD_NO_NONTYPE_ARGS
cout << b << endl; // results in 00000101
#endif
return 0;
}

View file

@ -0,0 +1,115 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* calc.cpp - RPN Calculator -- Illustration of the use of stacks.
* Section 10.2.1
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <stack>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Simulate the behavior of a simple integer calculator.
//
class CalculatorEngine
{
public:
enum binaryOperator { PLUS, MINUS, TIMES, DIVIDE };
int currentMemory () { return data.top(); }
void pushOperand (int value) { data.push (value); }
void doOperator (binaryOperator);
protected:
stack< int, vector<int,allocator<int> > > data;
};
void CalculatorEngine::doOperator (binaryOperator theOp)
{
int right = data.top();
data.pop();
int left = data.top();
data.pop();
switch (theOp)
{
case PLUS: data.push(left + right); break;
case MINUS: data.push(left - right); break;
case TIMES: data.push(left * right); break;
case DIVIDE: data.push(left / right); break;
}
}
int main()
{
cout << "Calculator example program, from Chapter 8" << endl;
cout << "Enter a legal RPN expression, end with p q (print and quit)" << endl;
int intval;
CalculatorEngine calc;
char c;
while (cin >> c)
switch (c)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
cin.putback(c);
cin >> intval;
calc.pushOperand(intval);
break;
case '+':
calc.doOperator(CalculatorEngine::PLUS); break;
case '-': calc.doOperator(CalculatorEngine::MINUS); break;
case '*': calc.doOperator(CalculatorEngine::TIMES); break;
case '/': calc.doOperator(CalculatorEngine::DIVIDE); break;
case 'p': cout << calc.currentMemory() << endl;
case 'q': cout << "End calculator program" << endl;
return 0; // quit program
}
return 0;
}

View file

@ -0,0 +1,111 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* codecvt.cpp - Example program of codecvt facet.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <sstream>
#include "codecvte.h"
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
mbstate_t state;
// three strings to use as buffers
string ins("\xfc \xcc \xcd \x61 \xe1 \xd9 \xc6 \xe6 \xf5");
string ins2(ins.size(),'.');
string outs(ins.size()/ex_codecvt().encoding(),'.');
// Print initial contents of buffers
cout << "Before:\n" << ins << endl;
cout << ins2 << endl;
cout << outs << endl << endl;
// Initialize buffers
string::iterator in_it = ins.begin();
string::iterator out_it = outs.begin();
string::const_iterator const_in_it = ins.begin();
string::const_iterator const_out_it = outs.begin();
// Create a user defined codecvt fact
// This facet converst from ISO Latin
// Alphabet No. 1 (ISO 8859-1) to
// U.S. ASCII code page 437
// This facet replaces the default for
// codecvt<char,char,mbstate_t>
locale loc(locale(),new ex_codecvt);
// Now get the facet from the locale
const codecvt<char,char,mbstate_t>& cdcvt =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<codecvt<char,char,mbstate_t> >(loc);
#else
use_facet(loc,(codecvt<char,char,mbstate_t>*)0);
#endif
// convert the buffer
cdcvt.in(state,ins.begin(),ins.end(),const_in_it,
outs.begin(),outs.end(),out_it);
cout << "After in:\n" << ins << endl;
cout << ins2 << endl;
cout << outs << endl << endl;
// Lastly, convert back to the original codeset
in_it = ins.begin();
out_it = outs.begin();
cdcvt.out(state, outs.begin(),outs.end(),const_out_it,
ins2.begin(),ins2.end(),in_it);
cout << "After out:\n" << ins << endl;
cout << ins2 << endl;
cout << outs << endl;
return 0;
}

View file

@ -0,0 +1,232 @@
/**************************************************************************
*
* codecvte.h - Example of user defined codecvt facet.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <locale>
#include <strstream>
#include <functional>
#include <algorithm>
#ifndef _RWSTD_NO_NAMESPACE
using std::codecvt;
using std::min;
#ifdef _RWSTD_NO_MBSTATE_T
using std::mbstate_t;
#endif
#endif
#define RWSTD_TABLE_SIZE 59
//
// This facet performs a conversion from Latin Alphabet No. 1
// (ISO 8859-1) to U.S. ASCII code page 437. Some conversions are one
// way (from ISO to ASCII, but not back again) because this ASCII
// code page has no equivilent to the ISO character.
//
class ex_codecvt : public codecvt<char,char,mbstate_t>
{
private:
static char table_[RWSTD_TABLE_SIZE][3];
protected:
virtual result do_in(mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
char* to, char* to_limit, char*& to_next) const
{
bool match;
int i = min(to_limit-to,from_end-from);
from_next = from;
to_next = to;
for (int j =0; j < i; j++)
{
match = false;
for (int k = 0; k < RWSTD_TABLE_SIZE; k++)
{
if (*from_next >= table_[k][0] &&
*from_next <= table_[k][1])
{
*to_next = table_[k][2];
match = true;
break;
}
}
if (!match)
*to_next = *from_next;
from_next++;
to_next++;
}
return ok;
}
virtual result do_out(mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
char* to, char* to_limit, char*& to_next) const
{
bool match;
int i = min(to_limit-to,from_end-from);
from_next = from;
to_next = to;
for (int j =0; j < i; j++)
{
match = false;
for (int k = 0; k < RWSTD_TABLE_SIZE; k++)
{
if (*from_next == table_[k][2] &&
table_[k][0] == table_[k][1])
{
*to_next = table_[k][1];
match = true;
break;
}
}
if (!match)
*to_next = *from_next;
from_next++;
to_next++;
}
return ok;
}
virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL
{ return false; }
virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL
{ return 1; }
virtual int do_length (const mbstate_t&, const char* from,
const char* end, size_t max) const
{ return min((size_t)(end - from),max); }
virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL
{ return INT_MAX; }
};
char ex_codecvt::table_[RWSTD_TABLE_SIZE][3] =
{ 0xa2, 0xa2, 0x9b,
0xa3, 0xa3, 0x9c,
0xa5, 0xa5, 0x9d,
0xa7, 0xa7, 0x15,
0xa8, 0xa8, 0x22,
0xaa, 0xaa, 0xa6,
0xab, 0xab, 0xae,
0xb5, 0xb5, 0xe6,
0xb6, 0xb6, 0x14,
0xb7, 0xb7, 0xfa,
0xba, 0xba, 0xa7,
0xbb, 0xbb, 0xaf,
0xbc, 0xbc, 0xac,
0xbd, 0xbd, 0xab,
0xbf, 0xbf, 0xa8,
0xc0, 0xc3, 0x41,
0xc4, 0xc4, 0x8e,
0xc5, 0xc5, 0x41,
0xc6, 0xc6, 0x92,
0xc7, 0xc7, 0x80,
0xc8, 0xc8, 0x45,
0xc9, 0xc9, 0x90,
0xca, 0xcb, 0x45,
0xcc, 0xcf, 0x49,
0xd1, 0xd1, 0xa5,
0xd2, 0xd5, 0x4f,
0xd6, 0xd6, 0x99,
0xd8, 0xd8, 0xed,
0xd9, 0xdb, 0x55,
0xdc, 0xdc, 0x9a,
0xdd, 0xdd, 0x59,
0xdf, 0xdf, 0xe1,
0xe0, 0xe0, 0x85,
0xe1, 0xe1, 0xa0,
0xe2, 0xe2, 0x83,
0xe3, 0xe3, 0x61,
0xe4, 0xe4, 0x84,
0xe5, 0xe5, 0x86,
0xe6, 0xe6, 0x91,
0xe7, 0xe7, 0x87,
0xe8, 0xe8, 0x8a,
0xe9, 0xe9, 0x82,
0xea, 0xea, 0x88,
0xeb, 0xeb, 0x89,
0xec, 0xec, 0x8d,
0xed, 0xed, 0xa1,
0xee, 0xee, 0x8c,
0xef, 0xef, 0x8b,
0xf1, 0xf1, 0xa4,
0xf2, 0xf2, 0x95,
0xf3, 0xf3, 0xa2,
0xf4, 0xf4, 0x93,
0xf5, 0xf5, 0x6f,
0xf6, 0xf6, 0x94,
0xf9, 0xf9, 0x97,
0xfa, 0xfa, 0xa3,
0xfb, 0xfb, 0x96,
0xfc, 0xfc, 0x81,
0xff, 0xff, 0x98 };

View file

@ -0,0 +1,76 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* collate.cpp - Example program of collate facet.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iostream>
#include <locale>
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
locale loc;
string s1("blue");
string s2("blues");
// Get a reference to the collate<char> facet
const collate<char>& co =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<collate<char> >(loc);
#else
use_facet(loc,(collate<char>*)0);
#endif
// Compare two strings
cout << co.compare(s1.begin(),s1.end(),
s2.begin(),s2.end()-1) << endl;
cout << co.compare(s1.begin(),s1.end(),
s2.begin(),s2.end()) << endl;
// Retrieve hash values for two strings
cout << co.hash(s1.begin(),s1.end()) << endl;
cout << co.hash(s2.begin(),s2.end()) << endl;
return 0;
}

View file

@ -0,0 +1,65 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* complex.cpp - Example program for complex. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <complex>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
complex<double> a(1.2, 3.4);
complex<double> b(-9.8, -7.6);
a += b;
a /= sin(b) * cos(a);
b *= log(a) + pow(b, a);
cout << "a = " << a << ", b = " << b << endl;
return 0;
}

View file

@ -0,0 +1,80 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* complx.cpp - Complex Number example program. Section 14.3
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <complex>
#include <utility>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef complex<double> dcomplex;
//
// Return roots of a quadratic equation.
//
pair<dcomplex, dcomplex> quadratic (dcomplex a, dcomplex b, dcomplex c)
{
dcomplex root = sqrt(b * b - 4.0 * a * c);
a = a * 2.0;
return make_pair ((-b + root) / a, (-b - root) / a);
}
int main ()
{
dcomplex a(2, 3);
dcomplex b(4, 5);
dcomplex c(6, 7);
pair<dcomplex, dcomplex> ans = quadratic(a, b, c);
cout << "Roots are " << ans.first << " and " << ans.second << endl;
return 0;
}

View file

@ -0,0 +1,162 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* concord.cpp - Concordance sample program. Section 9.3.3
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <map>
#include <list>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#include <string>
#include <ctype.h>
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Split a line of text into words.
//
void split (const string& text, const string& separators, list<string,allocator<string> > & words)
{
int n = text.length();
int start = text.find_first_not_of(separators);
while ((start >= 0) && (start < n))
{
int stop = text.find_first_of(separators, start);
if ((stop < 0) || (stop > n)) stop = n;
words.push_back (text.substr(start, stop-start));
start = text.find_first_not_of(separators, stop+1);
}
}
class concordance
{
typedef multimap<string, int, less<string>,allocator<string> > wordDictType;
public:
void addWord (string, int);
void readText (istream &);
void printConcordance (ostream &);
private:
wordDictType wordMap;
};
void concordance::addWord (string word, int line)
{
//
// First get range of entries with same key.
//
wordDictType::iterator low = wordMap.lower_bound(word);
wordDictType::iterator high = wordMap.upper_bound(word);
//
// Loop over entires, see if any match current line.
//
for ( ; low != high; ++low)
if ((*low).second == line)
return;
//
// Didn't occur, add now.
//
wordMap.insert(wordDictType::value_type(word, line));
}
void allLower (string & s)
{
for (int i = 0; i < s.size(); i++)
if (isupper(s[i]))
s[i] = tolower(s[i]);
}
void concordance::readText (istream & in)
{
string line;
for (int i = 1; getline(in, line, '\n'); i++)
{
allLower(line);
list<string,allocator<string> > words;
split(line, " ,.;:", words);
list<string,allocator<string> >::iterator wptr;
for (wptr = words.begin(); wptr != words.end(); ++wptr)
addWord(*wptr, i);
}
}
void concordance::printConcordance (ostream & out)
{
string lastword("");
wordDictType::iterator pairPtr;
wordDictType::iterator stop = wordMap.end();
for (pairPtr = wordMap.begin(); pairPtr != stop; ++pairPtr)
//
// If word is same as previous, just print line number.
//
if (lastword == (*pairPtr).first)
out << " " << (*pairPtr).second;
else
{
//
// First entry of word.
//
lastword = (*pairPtr).first;
cout << endl << lastword << ": " << (*pairPtr).second;
}
cout << endl;
}
int main ()
{
cout << "Concordance sample program, from Chapter 7" << endl;
cout << "Enter text, then end-of-file:" << endl;
concordance words;
words.readText(cin);
words.printConcordance(cout);
cout << "End of concordance sample program" << endl;
return 0;
}

View file

@ -0,0 +1,93 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* copyex.cpp - Example program for copy. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[4] = {1,2,3,4};
int d2[4] = {5,6,7,8};
//
// Set up three vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+4), v2(d2+0, d2+4), v3(d2+0, d2+4);
//
// Set up one empty vector.
//
vector<int,allocator<int> > v4;
//
// Copy v1 to v2.
//
copy(v1.begin(), v1.end(), v2.begin());
//
// Copy backwards v1 to v3.
//
copy_backward(v1.begin(), v1.end(), v3.end());
//
// Use insert iterator to copy into empty vector.
//
copy(v1.begin(), v1.end(), back_inserter(v4));
//
// Copy all four to cout.
//
ostream_iterator<int,char,char_traits<char> > out(cout," ");
copy(v1.begin(),v1.end(),out);
cout << endl;
copy(v2.begin(),v2.end(),out);
cout << endl;
copy(v3.begin(),v3.end(),out);
cout << endl;
copy(v4.begin(),v4.end(),out);
cout << endl;
return 0;
}

View file

@ -0,0 +1,78 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* count.cpp - Example program for counting number of elements in container.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int sequence[10] = {1,2,3,4,5,5,7,8,9,10};
int i=0,j=0,k=0;
//
// Set up a vector.
//
vector<int,allocator<int> > v(sequence+0, sequence+10);
count(v.begin(),v.end(),5,i); // Count fives
count(v.begin(),v.end(),6,j); // Count sixes
//
// Count all less than 8.
//
count_if(v.begin(), v.end(), bind2nd(less<int>(),8),k);
cout << i << " " << j << " " << k << endl;
return 0;
}

View file

@ -0,0 +1,75 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* ctype.cpp - Example program of ctype facet.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iostream>
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
locale loc;
string s1("blues Power");
// Get a reference to the ctype<char> facet
const ctype<char>& ct =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<ctype<char> >(loc);
#else
use_facet(loc,(ctype<char>*)0);
#endif
// Check the classification of the 'a' character
cout << ct.is(ctype_base::alpha,'a') << endl;
cout << ct.is(ctype_base::punct,'a') << endl;
// Scan for the first upper case character
cout << (char)*(ct.scan_is(ctype_base::upper,
s1.begin(),s1.end())) << endl;
// Convert characters to upper case
ct.toupper(s1.begin(),s1.end());
cout << s1 << endl;
return 0;
}

View file

@ -0,0 +1,103 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* deque.cpp - Example program for deque class. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <deque>
#include <string>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
deque<string,allocator<string> > deck_of_cards;
deque<string,allocator<string> > current_hand;
void initialize_cards(deque<string,allocator<string> >& cards)
{
cards.push_front("aceofspades");
cards.push_front("kingofspades");
cards.push_front("queenofspades");
cards.push_front("jackofspades");
cards.push_front("tenofspades");
//
// etc.
//
}
template <class It, class It2>
void print_current_hand(It start, It2 end)
{
while (start < end)
cout << *start++ << endl;
}
template <class It, class It2>
void deal_cards(It, It2 end)
{
for (int i=0;i<5;i++)
{
current_hand.insert(current_hand.begin(),*end);
deck_of_cards.erase(end++);
}
}
void play_poker()
{
initialize_cards(deck_of_cards);
deal_cards(current_hand.begin(),deck_of_cards.begin());
}
int main ()
{
play_poker();
print_current_hand(current_hand.begin(),current_hand.end());
return 0;
}

View file

@ -0,0 +1,83 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* distance.cpp - Example program for distance between two iterators.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include<iterator>
#include<vector>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Initialize a vector using an array.
//
int arr[6] = {3,4,5,6,7,8};
vector<int,allocator<int> > v(arr+0, arr+6);
//
// Declare a list iterator, s.b. a ForwardIterator.
//
vector<int,allocator<int> >::iterator itr = v.begin()+3;
//
// Output the original vector.
//
cout << "For the vector: ";
copy(v.begin(), v.end(), ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << endl;
cout << "When the iterator is initialized to point to " << *itr << endl;
//
// Use of distance.
//
vector<int,allocator<int> >::difference_type dist = 0;
distance(v.begin(), itr, dist);
cout << "The distance between the beginning and itr is " << dist << endl;
return 0;
}

View file

@ -0,0 +1,81 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* eqlrange.cpp - Example program for finding the valid range for insertion
* of a value in a container. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[11] = {0,1,2,2,3,4,2,2,2,6,7};
//
// Set up a vector.
//
vector<int,allocator<int> > v1(d1+0, d1+11);
//
// Try equal_range variants.
//
pair<iterator,iterator> p1 = equal_range(v1.begin(),v1.end(),3);
pair<iterator,iterator> p2 = equal_range(v1.begin(),v1.end(),2,less<int>());
//
// Output results.
//
cout << endl << "The equal range for 3 is: "
<< "( " << *p1.first << " , "
<< *p1.second << " ) " << endl << endl;
cout << endl << "The equal range for 2 is: "
<< "( " << *p2.first << " , "
<< *p2.second << " ) " << endl;
return 0;
}

View file

@ -0,0 +1,77 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* equal.cpp - Example program for comparing two ranges for equivalence.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[4] = {1,2,3,4};
int d2[4] = {1,2,4,3};
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+4), v2(d2+0, d2+4);
//
// Check for equality.
//
bool b1 = equal(v1.begin(), v1.end(), v2.begin());
bool b2 = equal(v1.begin(), v1.end(), v2.begin(),equal_to<int>());
//
// Both b1 and b2 are false.
//
cout << (b1 ? "TRUE" : "FALSE") << " "
<< (b2 ? "TRUE" : "FALSE") << endl;
return 0;
}

View file

@ -0,0 +1,85 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* except.cpp - Example program for exceptions. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <compnent.h>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#include <stdexcept>
#ifdef _RWSTD_NO_EXCEPTIONS
int main ()
{
cout << "Your compiler doesn't support exceptions!" << endl;
return 0;
}
#else
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
static void f() { throw runtime_error("a runtime error"); }
int main ()
{
//
// By wrapping the body of main in a try-catch block we can be
// assured that we'll catch all exceptions in the exception hierarchy.
// You can simply catch exception as is done below, or you can catch
// each of the exceptions in which you have an interest.
//
try
{
f();
}
catch (const exception& e)
{
cout << "Got an exception: " << e.what() << endl;
}
return 0;
}
#endif /*_RWSTD_NO_EXCEPTIONS*/

View file

@ -0,0 +1,101 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* exceptn.cpp - Illustrate the use of Standard exceptions.
* Section 13
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <string>
#include <stdexcept>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
#ifdef _RWSTD_NO_EXCEPTIONS
int main ()
{
cout << "Your compiler doesn't support exceptions!" << endl;
return 0;
}
#else
// A simple class to demonstrate throwing an exception
static void f() { throw runtime_error("a runtime error"); }
int main ()
{
string s;
// First we'll try to incite and catch an exception from
// the standard library string class.
// We'll try to replace at a position that is non-existant.
//
// By wrapping the body of main in a try-catch block we can be
// assured that we'll catch all exceptions in the exception hierarchy.
// You can simply catch exception as is done below, or you can catch
// each of the exceptions in which you have an interest.
try
{
s.replace(100,1,1,'c');
}
catch (const exception& e)
{
cout << "Got an exception: " << e.what() << endl;
}
// Now we'll throw our own exception using the function
// defined above.
try
{
f();
}
catch (const exception& e)
{
cout << "Got an exception: " << e.what() << endl;
}
return 0;
}
#endif /*_RWSTD_NO_EXCEPTIONS*/

View file

@ -0,0 +1,97 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* filebuf.cpp - basic_filebuf example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include<iostream>
#include<fstream>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
// create a read/write file-stream object on tiny char
// and attach it to the file "filebuf.out"
ofstream out("filebuf.dat",ios_base::in |
ios_base::out | ios_base::trunc );
// tie the istream object to the ofstream object
istream in(out.rdbuf());
// output to out
out << "Il errait comme un ame en peine";
// seek to the beginning of the file
in.seekg(0);
// output in to the standard output
cout << in.rdbuf() << endl;
// close the file "filebuf.out"
out.close();
// open the existing file "filebuf.out"
// and truncate it
out.open("filebuf.dat",ios_base::in |
ios_base::out | ios_base::trunc);
// set the buffer size
out.rdbuf()->pubsetbuf(0,4096);
// open the source code file
ifstream ins("filebuf.cpp");
//output it to filebuf.out
out << ins.rdbuf();
// seek to the beginning of the file
out.seekp(0);
// output the all file
cout << out.rdbuf();
return 0;
}

View file

@ -0,0 +1,96 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* fill.cpp - Example program for initializing a range with a given value.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[4] = {1,2,3,4};
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+4), v2(d1+0, d1+4);
//
// Set up one empty vector.
//
vector<int,allocator<int> > v3;
//
// Fill all of v1 with 9.
//
fill(v1.begin(), v1.end(), 9);
//
// Fill first 3 of v2 with 7.
//
fill_n(v2.begin(), 3, 7);
//
// Use insert iterator to fill v3 with 5 11's.
//
fill_n(back_inserter(v3), 5, 11);
//
// Copy all three to cout.
//
ostream_iterator<int,char,char_traits<char> > out(cout," ");
copy(v1.begin(),v1.end(),out);
cout << endl;
copy(v2.begin(),v2.end(),out);
cout << endl;
copy(v3.begin(),v3.end(),out);
cout << endl;
//
// Fill cout with 3 5's.
//
fill_n(ostream_iterator<int,char,char_traits<char> >(cout," "), 3, 5);
cout << endl;
return 0;
}

View file

@ -0,0 +1,84 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* find.cpp - Example program for finding an occurence of value in a
* sequence. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[10] = {0,1,2,2,3,4,2,2,6,7};
//
// Set up a vector.
//
vector<int,allocator<int> > v1(d1+0, d1+10);
//
// Try find.
//
iterator it1 = find(v1.begin(), v1.end(), 3);
//
// Try find_if.
//
iterator it2 = find_if(v1.begin(), v1.end(), bind1st(equal_to<int>(), 3));
//
// Try both adjacent_find variants.
//
iterator it3 = adjacent_find(v1.begin(), v1.end());
iterator it4 = adjacent_find(v1.begin(), v1.end(), equal_to<int>());
//
// Output results.
//
cout << *it1 << " " << *it2 << " " << *it3 << " " << *it4 << endl;
return 0;
}

View file

@ -0,0 +1,102 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* find_end.cpp - Example program for finding a subsequence.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[10] = {0,1,6,5,3,2,2,6,5,7};
int d2[4] = {6,5,0,0};
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+10), v2(d2+0, d2+2);
//
// Try both find_first_of variants.
//
iterator it1 = find_first_of(v1.begin(), v1.end(), v2.begin(), v2.end());
iterator it2 = find_first_of(v1.begin(), v1.end(), v2.begin(), v2.end(), equal_to<int>());
//
// Try both find_end variants.
//
iterator it3 = find_end(v1.begin(), v1.end(), v2.begin(), v2.end());
iterator it4 = find_end(v1.begin(), v1.end(), v2.begin(), v2.end(), equal_to<int>());
//
// Output results of find_first_of.
// Iterator now points to the first element that matches one of a set of values
//
if (it3 == it4 && it1 == it2)
{
cout << "For the vectors: ";
copy(v1.begin(),v1.end(),
ostream_iterator<int,char,char_traits<char> >(cout," " ));
cout << " and ";
copy(v2.begin(),v2.end(),
ostream_iterator<int,char,char_traits<char> >(cout," " ));
cout << endl << endl
<< "both versions of find_first_of point to: " << *it1 << endl;
//
// Output results of find_end.
// Iterator now points to the first element of the last find subsequence.
//
cout << endl << endl
<< "both versions of find_end point to: " << *it3 << endl;
}
return 0;
}

View file

@ -0,0 +1,85 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* find_f_o.cpp - Example program for finding a subsequence.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[10] = {0,1,2,2,3,4,2,2,6,7};
int d2[2] = {6,4};
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+10), v2(d2+0, d2+2);
//
// Try both find_first_of variants.
//
iterator it1 = find_first_of(v1.begin(), v1.end(), v2.begin(), v2.end());
find_first_of(v1.begin(), v1.end(), v2.begin(), v2.end(), equal_to<int>());
//
// Output results.
//
cout << "For the vectors: ";
copy(v1.begin(),v1.end(),
ostream_iterator<int,char,char_traits<char> >(cout," " ));
cout << " and ";
copy(v2.begin(),v2.end(),
ostream_iterator<int,char,char_traits<char> >(cout," " ));
cout << endl << endl
<< "both versions of find_first_of point to: " << *it1;
cout << endl;
return 0;
}

View file

@ -0,0 +1,86 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* for_each.cpp - Example program for applying a function to each element
* in a range. See Class Reference Section
*
* $Id: for_each.cpp,v 1.12 1996/08/28 01:16:49 smithey Exp $
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Function class that outputs its argument times x.
//
template <class Arg>
class out_times_x : private unary_function<Arg,void>
{
private:
Arg multiplier;
public:
out_times_x(const Arg& x) : multiplier(x) { }
void operator()(const Arg& x) { cout << x * multiplier << " " << endl; }
};
int main ()
{
int sequence[5] = {1,2,3,4,5};
//
// Set up a vector.
//
vector<int,allocator<int> > v(sequence+0, sequence+5);
//
// Setup a function object.
//
out_times_x<int> f2(2);
for_each(v.begin(),v.end(),f2); // Apply function
return 0;
}

View file

@ -0,0 +1,115 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* fstream.cpp - fstream example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
//
// stdlib/examples/manual/fstream.cpp
//
#include<iostream>
#include<fstream>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
// create a bi-directional fstream object
fstream inout("fstream.out",ios_base::in | ios_base::out | ios_base::trunc);
// output characters
inout << "Das ist die rede von einem man" << endl;
inout << "C'est l'histoire d'un home" << endl;
inout << "This is the story of a man" << endl;
char p[100];
// seek back to the beginning of the file
inout.seekg(0);
// extract the first line
inout.getline(p,100);
// output the first line to stdout
cout << endl << "Deutch :" << endl;
cout << p;
fstream::pos_type pos = inout.tellg();
// extract the seconf line
inout.getline(p,100);
// output the second line to stdout
cout << endl << "Francais :" << endl;
cout << p;
// extract the third line
inout.getline(p,100);
// output the third line to stdout
cout << endl << "English :" << endl;
cout << p;
// move the put sequence before
// the second line
inout.seekp(pos);
// replace the second line
inout << "This is the story of a man" << endl;
// replace the third line
inout << "C'est l'histoire d'un home";
// seek to the beginning of the file
inout.seekg(0);
// output the all content of the
// fstream object to stdout
cout << endl << endl << inout.rdbuf();
cout << endl;
return 0;
}

View file

@ -0,0 +1,103 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* funct_ob.cpp - Example program for function objects.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <functional>
#include <deque>
#include <vector>
#include <algorithm>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Create a new function object from unary_function.
//
template<class Arg>
class factorial : public unary_function<Arg, Arg>
{
public:
Arg operator() (const Arg& arg)
{
Arg a = 1;
for (Arg i = 2; i <= arg; i++)
a *= i;
return a;
}
};
int main ()
{
//
// Initialize a deque with an array of integers.
//
int init[7] = {1,2,3,4,5,6,7};
deque<int,allocator<int> > d(init+0, init+7);
//
// Create an empty vector to store the factorials.
//
vector<int,allocator<int> > v((size_t)7);
//
// Transform the numbers in the deque to their factorials and store
// in the vector.
//
transform(d.begin(), d.end(), v.begin(), factorial<int>());
//
// Print the results.
//
cout << "The following numbers: " << endl << " ";
copy(d.begin(), d.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << endl;
cout << "Have the factorials: " << endl << " ";
copy(v.begin(), v.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl;
return 0;
}

View file

@ -0,0 +1,109 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* generate.cpp - Example program for initializing a container with values
* produced by a value-generator class. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
//
// Value generator simply doubles the current value and returns it.
//
template <class T>
class generate_val
{
private:
T val_;
public:
generate_val(const T& val) : val_(val) {}
T& operator()() { val_ += val_; return val_; }
};
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[4] = {1,2,3,4};
generate_val<int> gen(1);
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+4), v2(d1+0, d1+4);
//
// Set up one empty vector.
//
vector<int,allocator<int> > v3;
//
// Generate values for all of v1.
//
generate(v1.begin(), v1.end(), gen);
//
// Generate values for first 3 of v2.
//
generate_n(v2.begin(), 3, gen);
//
// Use insert iterator to generate 5 values for v3.
//
generate_n(back_inserter(v3), 5, gen);
//
// Copy all three to cout.
//
ostream_iterator<int,char,char_traits<char> > out(cout," ");
copy(v1.begin(), v1.end(), out);
cout << endl;
copy(v2.begin(), v2.end(), out);
cout << endl;
copy(v3.begin(), v3.end(), out);
cout << endl;
//
// Generate 3 values for cout.
//
generate_n(ostream_iterator<int,char,char_traits<char> >(cout," "), 3, gen);
cout << endl;
return 0;
}

View file

@ -0,0 +1,159 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* graph.cpp - Graph program. Section 9.3.2
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <map>
#include <vector>
#include <queue>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#include <string>
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#ifndef __BORLANDC__
using namespace std::rel_ops; // RW_BUG
#endif
#endif
typedef map<string, int, less<string>,allocator<string> > stringVector;
typedef map<string, stringVector, less<string>,allocator<string> > graph;
struct DistancePair
{
unsigned first;
string second;
DistancePair() : first(0) {}
DistancePair(unsigned f, const string& s) : first(f), second(s) {}
};
bool operator< (const DistancePair& lhs, const DistancePair& rhs)
{
return lhs.first < rhs.first;
}
bool operator> (const DistancePair& lhs, const DistancePair& rhs)
{
return lhs.first > rhs.first;
}
string pendleton("Pendleton");
string pensacola("Pensacola");
string peoria("Peoria");
string phoenix("Phoenix");
string pierre("Pierre");
string pittsburgh("Pittsburgh");
string princeton("Princeton");
string pueblo("Pueblo");
graph cityMap;
void shortestDistance (graph& cityMap, string& start, stringVector& distances)
{
//
// Process a priority queue of distances to nodes.
//
priority_queue<DistancePair, vector<DistancePair,allocator<DistancePair> >,
greater<DistancePair> > que;
que.push(DistancePair(0, start));
while (! que.empty())
{
//
// Pull nearest city from queue.
//
int distance = que.top().first;
string city = que.top().second;
que.pop();
//
// If we haven't seen it already, process it.
//
if (0 == distances.count(city))
{
//
// Then add it to shortest distance map.
//
distances[city] = distance;
//
// And put values into queue.
//
const stringVector& cities = cityMap[city];
stringVector::const_iterator start = cities.begin();
stringVector::const_iterator stop = cities.end();
for (; start != stop; ++start)
que.push(DistancePair(distance + (*start).second,
(*start).first));
}
}
}
int main ()
{
cout << "Graph example program, from Chapter 7" << endl;
cityMap[pendleton][phoenix] = 4;
cityMap[pendleton][pueblo] = 8;
cityMap[pensacola][phoenix] = 5;
cityMap[peoria][pittsburgh] = 5;
cityMap[peoria][pueblo] = 3;
cityMap[phoenix][peoria] = 4;
cityMap[phoenix][pittsburgh] = 10;
cityMap[phoenix][pueblo] = 3;
cityMap[pierre][pendleton] = 2;
cityMap[pittsburgh][pensacola] = 4;
cityMap[princeton][pittsburgh] = 2;
cityMap[pueblo][pierre] = 3;
stringVector distances;
shortestDistance(cityMap, pierre, distances);
stringVector::iterator where;
for (where = distances.begin(); where != distances.end(); ++where)
cout << "Distance to: " << (*where).first << ":"
<< (*where).second << endl;
cout << "End of graph example program" << endl;
return 0;
}

View file

@ -0,0 +1,82 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* gslice_array.cpp -- Generalized array slice examples
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include "valarray.h" // Contains a valarray stream inserter
int main(void)
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int ibuf[27] = {0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10};
int buf13[9] = {13,13,13,13,13,13,13,13,13};
size_t len_buf[3] = {3,3,3};
size_t stride_buf[3] = {9,3,1};
// create a valarray of ints
valarray<int> vi(ibuf,27);
// print out the valarray
cout << vi << endl;
// Get a two dimensional diagonal slice out of the middle
valarray<size_t> len2(2);
len2[0] = 3;
len2[1] = 3;
valarray<size_t> stride2(2);
stride2[0] = 3;
stride2[1] = 10;
gslice_array<int> gsl = vi[gslice(0,len2,stride2)];
// print out the slice
cout << gsl << endl;
// Assign 13Æs to everything in the slice
gsl = valarray<int>(buf13,9);
// print out the slice and our original valarray
cout << gsl << endl << vi << endl;
return 0;
}

View file

@ -0,0 +1,98 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* gslice.cpp - Generalized slice example program.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include "valarray.h" // Contains a valarray stream inserter
int main(void)
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int ibuf[27] = {0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10};
size_t len_buf[3] = {3,3,3};
size_t stride_buf[3] = {9,3,1};
// create a valarray of ints
valarray<int> vi(ibuf,27);
// create length and stride valarrays
valarray<size_t> len(len_buf,3);
valarray<size_t> stride(stride_buf,3);
// print out the valarray
cout << vi << endl;
// Print out all three dimensions (the entire valarray)
cout << valarray<int>(vi[gslice(0,len,stride)]) << endl;
// Print a two dimensional slice out of the middle
valarray<size_t> len2(2);
len2[0] = 3;
len2[1] = 3;
valarray<size_t> stride2(2);
stride2[0] = 3;
stride2[1] = 1;
cout << valarray<int>(vi[gslice(9,len2,stride2)]) << endl;
// Print another two dimensional slice out of the middle
// but orthoganal to one we just did
stride2[0] = 9;
stride2[1] = 1;
cout << valarray<int>(vi[gslice(3,len2,stride2)]) << endl;
// Print out the last plane in the middle,
// (orthoganal to both of the previous ones)
stride2[0] = 3;
stride2[1] = 9;
cout << valarray<int>(vi[gslice(1,len2,stride2)]) << endl;
// Now how about a diagonal slice,
// upper left front to lower right back
stride2[0] = 3;
stride2[1] = 10;
cout << valarray<int>(vi[gslice(0,len2,stride2)]) << endl;
return 0;
}

View file

@ -0,0 +1,61 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* hasfacet.cpp - Example program of the hasfacet function template.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iostream>
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
locale loc;
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
cout << has_facet<ctype<char> >(loc) << endl;
#else
cout << has_facet(loc,(ctype<char>*)0) << endl;
#endif
return 0;
}

View file

@ -0,0 +1,123 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* heap_ops.cpp - Example program for heap operations.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[4] = {1,2,3,4};
int d2[4] = {1,3,2,4};
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+4), v2(d2+0, d2+4);
//
// Make heaps.
//
make_heap(v1.begin(), v1.end());
make_heap(v2.begin(), v2.end(), less<int>());
//
// v1 = (4,x,y,z) and v2 = (4,x,y,z)
//
// Note that x, y and z represent the remaining values in the
// container (other than 4). The definition of the heap and heap
// operations does not require any particular ordering
// of these values.
//
// Copy both vectors to cout.
//
ostream_iterator<int,char,char_traits<char> > out(cout," ");
copy(v1.begin(), v1.end(), out);
cout << endl;
copy(v2.begin(), v2.end(), out);
cout << endl;
//
// Now let's pop.
//
pop_heap(v1.begin(), v1.end());
pop_heap(v2.begin(), v2.end(), less<int>());
//
// Copy both vectors to cout.
//
copy(v1.begin(), v1.end(), out);
cout << endl;
copy(v2.begin(), v2.end(), out);
cout << endl;
//
// And push.
//
push_heap(v1.begin(), v1.end());
push_heap(v2.begin(), v2.end(), less<int>());
//
// Copy both vectors to cout.
//
copy(v1.begin(),v1.end(),out);
cout << endl;
copy(v2.begin(),v2.end(),out);
cout << endl;
//
// Now sort those heaps.
//
sort_heap(v1.begin(), v1.end());
sort_heap(v2.begin(), v2.end(), less<int>());
//
// Copy both vectors to cout.
//
copy(v1.begin(), v1.end(), out);
cout << endl;
copy(v2.begin(), v2.end(), out);
cout << endl;
return 0;
}

View file

@ -0,0 +1,256 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* icecream.cpp - priority queue example program. Section 11.3.1
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <queue>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Execution event in a descrete event driven simulation.
//
class event
{
public:
//
// Construct sets time of event.
//
event (unsigned int t) : time(t) { };
//
// Time is a public data field.
//
const unsigned int time;
//
// Execute event my invoking this method.
//
virtual void processEvent() = 0;
};
//
// Needed by some compilers.
//
inline void __destroy (event **) {}
struct eventComparison
{
bool operator () (const event * left, const event * right)
{ return left->time > right->time; }
};
//
// Framework for discrete event-driven simulations.
//
class simulation
{
public:
simulation () : eventQueue(), time(0) {}
void run ();
unsigned int time;
void scheduleEvent (event * newEvent) { eventQueue.push(newEvent); }
protected:
priority_queue<event*, vector<event *,allocator<event*> >, eventComparison > eventQueue;
};
void simulation::run ()
{
while (! eventQueue.empty())
{
event * nextEvent = eventQueue.top();
eventQueue.pop();
time = nextEvent->time;
nextEvent->processEvent();
delete nextEvent;
}
}
//
// Ice cream store simulation.
//
class storeSimulation : public simulation
{
public:
storeSimulation() : freeChairs(35), profit(0.0), simulation() { }
bool canSeat (unsigned int numberOfPeople);
void order (unsigned int numberOfScoops);
void leave (unsigned int numberOfPeople);
//
// Data fields.
//
unsigned int freeChairs;
double profit;
} theSimulation;
class arriveEvent : public event
{
public:
arriveEvent (unsigned int time, unsigned int groupSize)
: event(time), size(groupSize) { }
virtual void processEvent();
private:
unsigned int size;
};
class orderEvent : public event
{
public:
orderEvent (unsigned int time, unsigned int groupSize)
: event(time), size(groupSize) { }
virtual void processEvent();
private:
unsigned int size;
};
class leaveEvent : public event
{
public:
leaveEvent (unsigned int time, unsigned int groupSize)
: event(time), size(groupSize) { }
virtual void processEvent();
private:
unsigned int size;
};
//
// Return random integer between 0 and n.
//
int irand (int n) { return (rand()/10) % n; }
void arriveEvent::processEvent ()
{
if (theSimulation.canSeat(size))
theSimulation.scheduleEvent(new orderEvent(time + 1 + irand(4), size));
}
void orderEvent::processEvent ()
{
//
// Each person orders some number of scoops.
//
for (int i = 0; i < size; i++)
theSimulation.order(1 + irand(4));
//
// Then we schedule the leave event.
//
theSimulation.scheduleEvent(new leaveEvent(time + 1 + irand(10), size));
}
void leaveEvent::processEvent () { theSimulation.leave(size); }
//
// If sufficient room then seat customers.
//
bool storeSimulation::canSeat (unsigned int numberOfPeople)
{
cout << "Time: " << time;
cout << " group of " << numberOfPeople << " customers arrives";
if (numberOfPeople < freeChairs)
{
cout << " is seated" << endl;
freeChairs -= numberOfPeople;
return true;
}
else
{
cout << " no room, they leave" << endl;
return false;
}
}
//
// Service icecream, compute profits.
//
void storeSimulation::order (unsigned int numberOfScoops)
{
cout << "Time: " << time;
cout << " serviced order for " << numberOfScoops << endl;
profit += 0.35 * numberOfScoops;
}
//
// People leave, free up chairs.
//
void storeSimulation::leave (unsigned int numberOfPeople)
{
cout << "Time: " << time;
cout << " group of size " << numberOfPeople << " leaves" << endl;
freeChairs += numberOfPeople;
}
int main ()
{
cout << "Ice Cream Store simulation from Chapter 9" << endl;
//
// Load queue with some number of initial events.
//
unsigned int t = 0;
while (t < 20)
{
t += irand(6);
cout << "pumping queue with event " << t << endl;
theSimulation.scheduleEvent(new arriveEvent(t, 1 + irand(4)));
}
//
// Run the simulation.
//
theSimulation.run();
cout << "Total profits " << theSimulation.profit << endl;
cout << "End of ice cream store simulation" << endl;
return 0;
}

View file

@ -0,0 +1,158 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* ifstream.cpp - basic_ifstream example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
//
// stdlib/examples/manual/ifstream.cpp
//
#include<iostream>
#include<fstream>
#include<iomanip>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
long l= 20;
const char *ntbs="Le minot passait la piece a frotter";
char c;
char buf[50];
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
// create a read/write file-stream object on char
// and attach it to an ifstream object
ifstream in("ifstream.results.out",ios_base::in | ios_base::out |
ios_base::trunc);
if ( !in.is_open() )
#ifndef _RWSTD_NO_EXCEPTIONS
throw(ios_base::failure("Open error"));
#else
abort();
#endif
// tie the ostream object to the ifstream object
ostream out(in.rdbuf());
// output ntbs in out
out << ntbs << endl;
// seek to the beginning of the file
in.seekg(0);
// output each word on a separate line
while ( in.get(c) )
{
if ( ifstream::traits_type::eq(c,' ') )
cout << endl;
else
cout << c;
}
cout << endl << endl;
// move back to the beginning of the file
in.seekg(0);
// clear the state flags
in.clear();
// does the same thing as the previous code
// output each word on a separate line
while ( in >> buf )
cout << buf << endl;
cout << endl << endl;
// output the base info before each integer
out << showbase;
ostream::pos_type pos= out.tellp();
// output l in hex with a field with of 20
out << hex << setw(20) << l << endl;
// output l in oct with a field with of 20
out << oct << setw(20) << l << endl;
// output l in dec with a field with of 20
out << dec << setw(20) << l << endl;
// move back to the beginning of the file
in.seekg(0);
// output the all file
cout << in.rdbuf();
// clear the flags
in.clear();
// seek the input sequence to pos
in.seekg(pos);
int a,b,d;
in.unsetf(ios_base::basefield);
// read the previous outputted integer
in >> a >> b >> d;
// output 3 times 20
cout << a << endl << b << endl << d << endl;
#ifndef _RWSTD_NO_EXCEPTIONS
}
catch( ios_base::failure var )
{
cout << var.what();
}
#endif
return 0;
}

View file

@ -0,0 +1,83 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* includes.cpp - Example program of basic set operation for sorted
* sequences. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <set>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Initialize some sets.
//
int a1[10] = {1,2,3,4,5,6,7,8,9,10};
int a2[6] = {2,4,6,8,10,12};
int a3[4] = {3,5,7,8};
set<int, less<int>,allocator<int> > all(a1+0, a1+10), even(a2+0, a2+6), smalll(a3+0, a3+4);
//
// Demonstrate includes.
//
cout << "The set: ";
copy(all.begin(),all.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
bool answer = includes(all.begin(), all.end(), smalll.begin(), smalll.end());
cout << endl << (answer ? "INCLUDES " : "DOES NOT INCLUDE ");
copy(smalll.begin(),smalll.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
answer = includes(all.begin(), all.end(), even.begin(), even.end());
cout << ", and" << endl << (answer ? "INCLUDES" : "DOES NOT INCLUDE ");
copy(even.begin(),even.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << endl;
return 0;
}

View file

@ -0,0 +1,79 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* indirect_array.cpp -- Indirect array examples
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include "valarray.h" // Contains a valarray stream inserter
int main(void)
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int ibuf[10] = {0,1,2,3,4,5,6,7,8,9};
size_t sbuf[6] = {0,2,3,4,7,8};
// create a valarray of ints
valarray<int> vi(ibuf,10);
// create a valarray of indices for a selector
valarray<size_t> selector(sbuf,6);
// print out the valarray<int>
cout << vi << endl;
// Get a indirect_array
// and assign that indirect to another valarray
indirect_array<int> select = vi[selector];
valarray<int> vi3 = select;
// print out the selective array
cout << vi3 << endl;
// Double the selected values
select += vi3;
// print out vi1 again
cout << vi << endl;
return 0;
}

View file

@ -0,0 +1,91 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* inr_prod.cpp - Example program computes the inner product A X B of two
* ranges A and B. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <numeric> // For inner_product.
#include <list> // For list.
#include <vector> // For vectors.
#include <functional> // For plus and minus.
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Initialize a list and an int using arrays of ints.
//
int a1[3] = {6, -3, -2};
int a2[3] = {-2, -3, -2};
list<int,allocator<int> > l(a1+0, a1+3);
vector<int,allocator<int> > v(a2+0, a2+3);
//
// Calculate the inner product of the two sets of values.
//
int inner_prod = inner_product(l.begin(), l.end(), v.begin(), 0);
//
// Calculate a wacky inner product using the same values.
//
int wacky = inner_product(l.begin(), l.end(), v.begin(), 0,
plus<int>(), minus<int>());
//
// Print the output.
//
cout << "For the two sets of numbers: " << endl << " ";
copy(v.begin(),v.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl << " and ";
copy(l.begin(),l.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << "," << endl << endl;
cout << "The inner product is: " << inner_prod << endl;
cout << "The wacky result is: " << wacky << endl;
return 0;
}

View file

@ -0,0 +1,108 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* ins_itr.cpp - Example program of insert iterator.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iterator>
#include <deque>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Initialize a deque using an array.
//
int arr[4] = { 3,4,7,8 };
deque<int,allocator<int> > d(arr+0, arr+4);
//
// Output the original deque.
//
cout << "Start with a deque: " << endl << " ";
copy(d.begin(), d.end(), ostream_iterator<int,char,char_traits<char> >(cout," "));
//
// Insert into the middle.
//
insert_iterator<deque<int,allocator<int> > > ins(d, d.begin()+2);
*ins = 5; *ins = 6;
//
// Output the new deque.
//
cout << endl << endl;
cout << "Use an insert_iterator: " << endl << " ";
copy(d.begin(), d.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
//
// A deque of four 1s.
//
deque<int,allocator<int> > d2(4, 1);
//
// Insert d2 at front of d.
//
copy(d2.begin(), d2.end(), front_inserter(d));
//
// Output the new deque.
//
cout << endl << endl;
cout << "Use a front_inserter: " << endl << " ";
copy(d.begin(), d.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
//
// Insert d2 at back of d.
//
copy(d2.begin(), d2.end(), back_inserter(d));
//
// Output the new deque.
//
cout << endl << endl;
cout << "Use a back_inserter: " << endl << " ";
copy(d.begin(), d.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
cout << endl;
return 0;
}

View file

@ -0,0 +1,77 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* io_iter.cpp - Example program of iterator . See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iterator>
#include <vector>
#include <numeric>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
vector<int,allocator<int> > d;
int total = 0;
//
// Collect values from cin until end of file
// Note use of default constructor to get ending iterator
//
cout << "Enter a sequence of integers (eof to quit): " ;
copy(istream_iterator<int,char,char_traits<char>,ptrdiff_t >(cin),
istream_iterator<int,char,char_traits<char>,ptrdiff_t >(),
inserter(d,d.begin()));
//
// stream the whole vector and the sum to cout
//
copy(d.begin(),d.end()-1,
ostream_iterator<int,char,char_traits<char> >(cout," + "));
if (d.size())
cout << *(d.end()-1) << " = " <<
accumulate(d.begin(),d.end(),total) << endl;
return 0;
}

View file

@ -0,0 +1,57 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* isalnum.cpp - Example program of isalnum convience function.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <iostream>
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
locale loc;
cout << isalnum('a',loc) << endl;
cout << isalnum(',',loc) << endl;
return 0;
}

View file

@ -0,0 +1,84 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* istreambuf_iterator.cpp - istreambuf_iterator example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include<iostream>
#include<fstream>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
// open the file is_iter.out for reading and writing
ofstream out("is_iter.out", ios_base::out | ios_base::in | ios_base::trunc);
// output the example sentence into the file
out << "Ceci est un simple example pour demontrer le" << endl;
out << "fonctionement de istreambuf_iterator";
// seek to the beginning of the file
out.seekp(0);
// construct an istreambuf_iterator pointing to
// the ofstream object underlying streambuffer
istreambuf_iterator<char,char_traits<char> > iter(out.rdbuf());
// construct an end of stream iterator
istreambuf_iterator<char,char_traits<char> > end_of_stream_iterator;
cout << endl;
// output the content of the file
while( !iter.equal(end_of_stream_iterator) )
// use both operator++ and operator*
cout << *iter++;
cout << endl;
return 0;
}

View file

@ -0,0 +1,145 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* istringstream.cpp - basic_istringstream example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include<iostream>
#include<sstream>
#include<string>
#include<iomanip>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
long l= 20;
#ifndef _RWSTD_NO_WIDE_CHAR
wchar_t *ntbs=L"Il avait l'air heureux";
wchar_t c;
wchar_t buf[50];
// create a read/write string-stream object on wide char
// and attach it to an wistringstream object
wistringstream in(ios_base::in | ios_base::out);
// tie the ostream object to the wistringstream object
wostream out(in.rdbuf());
// output ntbs in out
out << ntbs;
// output each word on a separate line
while ( in.get(c) )
{
if ( wistringstream::traits_type::eq(c,L' ') )
wcout << endl;
else
wcout << c;
}
wcout << endl << endl;
// move back the input sequence to the beginning
in.seekg(0);
// clear the state flags
in.clear();
// does the same thing as the previous code
// output each word on a separate line
while ( in >> buf )
wcout << buf << endl;
wcout << endl << endl;
#endif
// create a tiny string object
string test_string("Il dormait pour l'eternite");
// create a read/write string-stream object on char
// and attach it to an istringstream object
istringstream in_bis(ios_base:: in | ios_base::out |
ios_base::app );
// create an ostream object
ostream out_bis(in_bis.rdbuf());
// initialize the string-buffer with test_string
in_bis.str(test_string);
out_bis << endl;
// output the base info before each integer
out_bis << showbase;
ostream::pos_type pos= out_bis.tellp();
// output l in hex with a field with of 20
out_bis << hex << setw(20) << l << endl;
// output l in oct with a field with of 20
out_bis << oct << setw(20) << l << endl;
// output l in dec with a field with of 20
out_bis << dec << setw(20) << l << endl;
// output the all buffer
cout << in_bis.rdbuf();
// seek the input sequence to pos
in_bis.seekg(pos);
int a,b,d;
in_bis.unsetf(ios_base::basefield);
// read the previous outputted integer
in_bis >> a >> b >> d;
// output 3 times 20
cout << a << endl << b << endl << d << endl;
return 0;
}

View file

@ -0,0 +1,142 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* istream1.cpp - istream example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include<iostream>
#include<istream>
#include<fstream>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
float f= 3.14159;
int i= 3;
char s[200];
// open a file for read and write operations
ofstream out("example", ios_base::in | ios_base::out
| ios_base::trunc);
// tie the istream object to the ofstream filebuf
istream in (out.rdbuf());
// output to the file
out << "He lifted his head and pondered." << endl;
out << f << endl;
out << i << endl;
// seek to the beginning of the file
in.seekg(0);
f = i = 0;
// read from the file using formatted functions
in >> s >> f >> i;
// seek to the beginning of the file
in.seekg(0,ios_base::beg);
// output the all file to the standard output
cout << in.rdbuf();
// seek to the beginning of the file
in.seekg(0);
// read the first line in the file
// "He lifted his head and pondered."
in.getline(s,100);
cout << s << endl;
// read the second line in the file
// 3.14159
in.getline(s,100);
cout << s << endl;
// seek to the beginning of the file
in.seekg(0);
// read the first line in the file
// "He lifted his head and pondered."
in.get(s,100);
// remove the newline character
in.ignore();
cout << s << endl;
// read the second line in the file
// 3.14159
in.get(s,100);
cout << s << endl;
// remove the newline character
in.ignore();
// store the current file position
istream::pos_type position = in.tellg();
out << "replace the int" << endl;
// move back to the previous saved position
in.seekg(position);
// output the remain of the file
// "replace the int"
// this is equivalent of
// cout << in.rdbuf();
while( !ifstream::traits_type::eq_int_type( in.peek(),
ifstream::traits_type::eof()) )
cout << ifstream::traits_type::to_char_type(in.get());
cout << "\n\n\n" << flush;
return 0;
}

View file

@ -0,0 +1,83 @@
#include "stlexam.h"
#pragma hdrstop
/***************************************************************************
*
* istrstream.cpp - istrstream example
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include<iostream>
#include<strstream>
int main ( )
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
const char* p="C'est pas l'homme qui prend la mer, ";
char* s="c'est la mer qui prend l'homme";
// create an istrstream object and initialize
// the underlying strstreambuf with p
istrstream in_first(p);
// create an istrstream object and initialize
// the underlying strstreambuf with s
istrstream in_next(s);
// create an strstream object
strstream out;
// output the content of in_first and
// in_next to out
out << in_first.rdbuf() << in_next.str();
// output the content of out to stdout
cout << endl << out.rdbuf() << endl;
// output the content of in_first to stdout
cout << endl << in_first.str();
// output the content of in_next to stdout
cout << endl << in_next.rdbuf() << endl;
return 0;
}

View file

@ -0,0 +1,78 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* lex_comp.cpp - Example program compares to ranges lexicographically.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[5] = {1,3,5,32,64};
int d2[5] = {1,3,2,43,56};
//
// Set up vector.
//
vector<int,allocator<int> > v1(d1+0, d1+5), v2(d2+0, d2+5);
//
// Is v1 less than v2 (I think not).
//
bool b1 = lexicographical_compare(v1.begin(),v1.end(),v2.begin(),v2.end());
//
// Is v2 less than v1 (yup, sure is).
//
bool b2 = lexicographical_compare(v2.begin(), v2.end(),
v1.begin(), v1.end(), less<int>());
cout << (b1 ? "TRUE" : "FALSE") << " "
<< (b2 ? "TRUE" : "FALSE") << endl;
return 0;
}

View file

@ -0,0 +1,71 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* limits.cpp - Example program of numeric limits class used for
* representing information about scalar types.
* See Class Reference Section.
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <limits>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
numeric_limits<float> float_info;
if (float_info.is_specialized && float_info.has_infinity)
{
//
// Get value of infinity.
//
cout << float_info.infinity() << endl;
}
return 0;
}

View file

@ -0,0 +1,114 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* list.cpp - Example program of list class. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <list>
#include <string>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Print out a list of strings.
//
ostream& operator<< (ostream& out, const list<string,allocator<string> >& l)
{
copy(l.begin(), l.end(),
ostream_iterator<string,char,char_traits<char> >(out," "));
return out;
}
int main ()
{
//
// Create a list of critters.
//
list<string,allocator<string> > critters;
int i;
//
// Insert several critters.
//
critters.insert(critters.begin(),"antelope");
critters.insert(critters.begin(),"bear");
critters.insert(critters.begin(),"cat");
//
// Print out the list.
//
cout << critters << endl;
//
// Change cat to cougar.
//
*find(critters.begin(),critters.end(),"cat") = "cougar";
cout << critters << endl;
//
// Put a zebra at the beginning, an ocelot ahead of antelope,
// and a rat at the end.
//
critters.push_front("zebra");
critters.insert(find(critters.begin(),critters.end(),"antelope"),"ocelot");
critters.push_back("rat");
cout << critters << endl;
//
// Sort the list (Use list's sort function since the
// generic algorithm requires a random access iterator
// and list only provides bidirectional)
//
critters.sort();
cout << critters << endl;
//
// Now let's erase half of the critters.
//
int half = critters.size() / 2;
for (i = 0; i < half; ++i)
critters.erase(critters.begin());
cout << critters << endl;
return 0;
}

View file

@ -0,0 +1,93 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* locale.cpp - Example program for the locale class.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <string>
#include <vector>
#include <iostream>
#include "codecvte.h"
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
locale loc; // Default locale
// Construct new locale using default locale plus
// user defined codecvt facet
// This facet converts from ISO Latin
// Alphabet No. 1 (ISO 8859-1) to
// U.S. ASCII code page 437
// This facet replaces the default for
// codecvt<char,char,mbstate_t>
locale my_loc(loc,new ex_codecvt);
// imbue modified locale onto cout
locale old = cout.imbue(my_loc);
cout << "A \x93 jolly time was had by all" << endl;
cout.imbue(old);
cout << "A jolly time was had by all" << endl;
// Create a vector of strings
vector<string,allocator<string> > v;
v.insert(v.begin(),"antelope");
v.insert(v.begin(),"bison");
v.insert(v.begin(),"elk");
copy(v.begin(),v.end(),
ostream_iterator<string,char,char_traits<char> >(cout," "));
cout << endl;
// Sort the strings using the locale as a comparitor
sort(v.begin(),v.end(),loc);
copy(v.begin(),v.end(),
ostream_iterator<string,char,char_traits<char> >(cout," "));
cout << endl;
return 0;
}

View file

@ -0,0 +1,226 @@
#==========================================================================
#
# makefile - makefile for examples
#
#==========================================================================
#
# (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
# ALL RIGHTS RESERVED
#
# The software and information contained herein are proprietary to, and
# comprise valuable trade secrets of, Rogue Wave Software, Inc., which
# intends to preserve as trade secrets such software and information.
# This software is furnished pursuant to a written license agreement and
# may be used, copied, transmitted, and stored only in accordance with
# the terms of such license and with the inclusion of the above copyright
# notice. This software and information or any other copies thereof may
# not be provided or otherwise made available to any other person.
#
# Notwithstanding any other lease or license that may pertain to, or
# accompany the delivery of, this computer software and information, the
# rights of the Government regarding its use, reproduction and disclosure
# are as set forth in Section 52.227-19 of the FARS Computer
# Software-Restricted Rights clause.
#
# Use, duplication, or disclosure by the Government is subject to
# restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
# Technical Data and Computer Software clause at DFARS 252.227-7013.
# Contractor/Manufacturer is Rogue Wave Software, Inc.,
# P.O. Box 2328, Corvallis, Oregon 97339.
#
# This computer software and information is distributed with "restricted
# rights." Use, duplication or disclosure is subject to restrictions as
# set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
# Computer Software-Restricted Rights (April 1985)." If the Clause at
# 18-52.227-74 "Rights in Data General" is specified in the contract,
# then the "Alternate III" clause applies.
#
#==========================================================================
#
# Makefile for the Rogue Wave Standard Library package, using
# Borland C++ with a Win32 target.
#
# Note ONLY the Borland-supplied "make" command
# should be used.
#
#==========================================================================
!include makeincl.inc
######################## Targets #################################
ALLEXES = \
accum.exe \
adj_diff.exe \
advance.exe \
alg1.exe \
alg2.exe \
alg3.exe \
alg4.exe \
alg5.exe \
alg6.exe \
alg7.exe \
auto_ptr.exe \
b_search.exe \
binders.exe \
bitset.exe \
calc.exe \
codecvt.exe \
collate.exe \
complex.exe \
complx.exe \
concord.exe \
copyex.exe \
count.exe \
ctype.exe \
deque.exe \
distance.exe \
eqlrange.exe \
equal.exe \
except.exe \
exceptn.exe \
filebuf.exe \
fill.exe \
find.exe \
find_end.exe \
find_f_o.exe \
for_each.exe \
fstream.exe \
funct_ob.exe \
generate.exe \
graph.exe \
gslc_ary.exe \
gslice.exe \
hasfacet.exe \
heap_ops.exe \
icecream.exe \
ifstream.exe \
includes.exe \
indr_ary.exe \
inr_prod.exe \
ins_itr.exe \
io_iter.exe \
isalnum.exe \
istbufit.exe \
istngstr.exe \
istream1.exe \
istrstre.exe \
lex_comp.exe \
limits.exe \
list.exe \
locale.exe \
map.exe \
mask_ary.exe \
max.exe \
max_elem.exe \
memfunc.exe \
memfunrf.exe \
merge.exe \
mismatch.exe \
moneyget.exe \
moneyput.exe \
monpunct.exe \
multimap.exe \
multiset.exe \
mutex.exe \
negator.exe \
nthelem.exe \
numget.exe \
numpunct.exe \
numput.exe \
ostbufit.exe \
ostream1.exe \
ostream2.exe \
p_queue.exe \
partsort.exe \
partsum.exe \
permute.exe \
pnt2fnct.exe \
prtition.exe \
queue.exe \
radix.exe \
remove.exe \
replace.exe \
rev_itr.exe \
reverse.exe \
rndshufl.exe \
rotate.exe \
search.exe \
set_diff.exe \
set_intr.exe \
set_s_di.exe \
set_unin.exe \
setex.exe \
sieve.exe \
slc_ary.exe \
slice.exe \
sort.exe \
spell.exe \
stack.exe \
stngstre.exe \
stocks.exe \
string.exe \
strngbuf.exe \
strstrbf.exe \
strstrea.exe \
swap.exe \
tele.exe \
timeget.exe \
timeput.exe \
toupper.exe \
trnsform.exe \
ul_bound.exe \
unique.exe \
usefacet.exe \
valarray.exe \
vector.exe \
widwork.exe \
all : rwstdmsg.dll messages.exe allobjs $(ALLEXES)
all : allobjs $(ALLEXES)
allobjs: $(ALLEXES:.exe=.obj)
clean:
-@if exist *.obj del *.obj >nul
-@if exist *.lib del *.lib >nul
-@if exist rwstdmsg.res del rwstdmsg.res >nul
-@if exist *.exe del *.exe >nul
-@if exist *.dll del *.dll >nul
-@if exist *.tds del *.tds >nul
-@if exist $(PCHROOT).* del $(PCHROOT).* >nul
runall: all $(ALLEXES)
#
# Warning: there are quite a few exe's here that will run. Also, several
# of the examples require input from stdin.
#
& $?
########################### Explicit Rules #######################
rwstdmsg.obj: rwstdmsg.cpp
$(CPP) $(CPPFLAGS) -tWD$(TARGSUF) -c {$? }
rwstdmsg.res: rwstdmsg.rc
$(RC) $(RCFLAGS) $?
rwstdmsg.dll: rwstdmsg.obj rwstdmsg.res
start $(LINKER) $(LINKFLAGS) $(LINKSTARTUP) rwstdmsg.obj ,$*,,$(LINKLIBS),,rwstdmsg.res
messages.exe: messages.obj rwstdmsg.dll
$(CPP) $(CPPFLAGS) messages.obj rwstdmsg.lib
########################### Implicit Rules #######################
.cpp.obj:
$(CPP) $(CPPFLAGS) -c {$? }
.cpp.i:
$(CPP32) $(CPPFLAGS) -c -Sr -Sd {$? }
.obj.exe:
$(CPP) $(CPPFLAGS) $<

View file

@ -0,0 +1,193 @@
#==========================================================================
#
# makeincl.bcc - header file Borland C++ makefiles
#
#==========================================================================
#
# (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
# ALL RIGHTS RESERVED
#
# The software and information contained herein are proprietary to, and
# comprise valuable trade secrets of, Rogue Wave Software, Inc., which
# intends to preserve as trade secrets such software and information.
# This software is furnished pursuant to a written license agreement and
# may be used, copied, transmitted, and stored only in accordance with
# the terms of such license and with the inclusion of the above copyright
# notice. This software and information or any other copies thereof may
# not be provided or otherwise made available to any other person.
#
# Notwithstanding any other lease or license that may pertain to, or
# accompany the delivery of, this computer software and information, the
# rights of the Government regarding its use, reproduction and disclosure
# are as set forth in Section 52.227-19 of the FARS Computer
# Software-Restricted Rights clause.
#
# Use, duplication, or disclosure by the Government is subject to
# restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
# Technical Data and Computer Software clause at DFARS 252.227-7013.
# Contractor/Manufacturer is Rogue Wave Software, Inc.,
# P.O. Box 2328, Corvallis, Oregon 97339.
#
# This computer software and information is distributed with "restricted
# rights." Use, duplication or disclosure is subject to restrictions as
# set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
# Computer Software-Restricted Rights (April 1985)." If the Clause at
# 18-52.227-74 "Rights in Data General" is specified in the contract,
# then the "Alternate III" clause applies.
#
#==========================================================================
#
# Header file for makefiles for the Rogue Wave Standard Library package,
# using Borland C++ with a Win32 target.
#
#==========================================================================
#
# Usage:
#
#
# make -fmakefile.bcc -DBINDING=<binding> -DTHREAD=<threads> \
# -DBMODE=<build mode> -DENVIRON=<environ>
#
#
# <environ> may be... for...
# ---------------------- ------------------------------------------
# *WIN32 32Bit Windows environment
#
# <binding> may be... for...
# ---------------------- ------------------------------------------
# *STATIC a statically linked version of the library
# DLL a dynamically linked version of the library
#
#
# <thread> may be... for...
# ---------------------- ------------------------------------------
# *SINGLE use with single-threaded applications
# MULTI an "MT-safe" version of the library
#
#
# <build mode> may be... for...
# ---------------------- ------------------------------------------
# DEBUG a debug version of the library
# *RELEASE a release version of the library
#
#
#==========================================================================
#
# Examples:
#
# (Assume building under Windows NT or 95):
# make -fmakefile.bcc BINDING=DLL THREAD=MULTI
# // builds or uses a flat-model dll version of the library, suitable for
# // use with multi-threaded applications, under Windows NT/95
#
#==========================================================================
###################################################################
#
# Borland specific directives ---
#
.SWAP
.AUTODEPEND
###################################################################
#
# set default values:
!ifndef ENVIRON
ENVIRON = WIN32
!endif
!ifndef BINDING
BINDING = STATIC
!endif
!ifndef THREAD
THREAD = MULTI
!endif
!ifndef BMODE
BMODE = RELEASE
!endif
###################################################################
#
# Flag illegal options:
#
!if $(ENVIRON) != WIN32
! error Illegal value for ENVIRON option
!endif
!if $(BINDING) != DLL && $(BINDING) != STATIC
! error Illegal value for BINDING option
!endif
!if $(THREAD) != SINGLE && $(THREAD) != MULTI
! error Illegal value for THREAD option
!endif
!if $(BMODE) != RELEASE && $(BMODE) != DEBUG
! error Illegal value for BMODE option
!endif
###################################################################
#
# Set tool and version names:
!if $(ENVIRON) == WIN32
CPP = bcc32
CPP32 = cpp32
LIBRARIAN = tlib /P128
LINKER = ilink32
RC = brc32
ENVNAME =
!endif
###################################################################
#
# Set the various flags:
!if $(BMODE) == DEBUG
DBGOPT= -v -N -x -xp
CCLINKOPT = -lGn
!else
CCLINKOPT = -lGn
!endif
!if $(THREAD) == MULTI
CCLINKOPT = $(CCLINKOPT) -tWM
LIBSUF=mt
!else
CCLINKOPT = $(CCLINKOPT) -tWM-
LIBSUF=
!endif
###################################################################
#
# Set any relevant defines (-Dxxx)
DEFOPTS =
!if $(BINDING) == DLL
DEFOPTS=$(DEFOPTS) -tWCR
TARGSUF=R
LIBSUF=$(LIBSUF)i
!else
DEFOPTS = $(DEFOPTS) -tWC
LIBSUF=$(LIBSUF)
TARGSUF=
!endif
###################################################################
#
# Set any compiler options
PCHROOT=stl_pch
CCOPTS = -w- -jb -j1 -Hc -H=$(PCHROOT).csm
#Compile flags:
CPPFLAGS= $(CCOPTS) $(DBGOPT) $(ENVOPTS) $(DEFOPTS) $(THROPTS) $(CCLINKOPT)
LINKFLAGS= -Gn -Gi -Tpd -aa -L$(MAKEDIR)\..\lib -x
LINKSTARTUP= c0d32.obj
LINKLIBS=import32.lib cw32$(LIBSUF).lib
RCFLAGS= -r -i$(MAKEDIR)\..\include;$(MAKEDIR)\..\include\windows

View file

@ -0,0 +1,126 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* map.cpp - Example program of map. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <compnent.h>
#include <string>
#include <map>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
namespace std {
#endif
typedef map<string, int, less<string>,allocator<string> > months_type;
//
// Print out a pair.
//
template <class First, class Second>
ostream& operator<< (ostream& out, const pair<First,Second> & p)
{
cout << p.first << " has " << p.second << " days";
return out;
}
//
// Print out a map.
//
ostream& operator<< (ostream& out, const months_type & l)
{
copy(l.begin(),l.end(), ostream_iterator
<months_type::value_type,char,char_traits<char> >(cout,"\n"));
return out;
}
#ifndef _RWSTD_NO_NAMESPACE
}
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Create a map of months and the number of days in the month.
//
months_type months;
typedef months_type::value_type value_type;
//
// Put the months in the multimap.
//
months.insert(value_type(string("January"), 31));
months.insert(value_type(string("Febuary"), 28));
months.insert(value_type(string("Febuary"), 29));
months.insert(value_type(string("March"), 31));
months.insert(value_type(string("April"), 30));
months.insert(value_type(string("May"), 31));
months.insert(value_type(string("June"), 30));
months.insert(value_type(string("July"), 31));
months.insert(value_type(string("August"), 31));
months.insert(value_type(string("September"), 30));
months.insert(value_type(string("October"), 31));
months.insert(value_type(string("November"), 30));
months.insert(value_type(string("December"), 31));
//
// Print out the months. Second Febuary is not present.
//
cout << months << endl;
//
// Find the Number of days in June.
//
months_type::iterator p = months.find(string("June"));
//
// Print out the number of days in June.
//
if (p != months.end())
cout << endl << *p << endl;
return 0;
}

View file

@ -0,0 +1,77 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* mask_array.cpp -- Mask array examples
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include "valarray.h" // Contains a valarray stream inserter
int main(void)
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int ibuf[10] = {0,1,2,3,4,5,6,7,8,9};
bool mbuf[10] = {1,0,1,1,1,0,0,1,1,0};
// create a valarray of ints
valarray<int> vi(ibuf,10);
// create a valarray of bools for a mask
valarray<bool> mask(mbuf,10);
// print out the valarray<int>
cout << vi << endl;
// Get a mask array and assign that mask to another array
mask_array<int> msk = vi[mask];
valarray<int> vi3 = msk;
// print out the masked_array
cout << vi3 << endl;
// Double the masked values
msk += vi3;
// print out vi1 again
cout << vi << endl;
return 0;
}

View file

@ -0,0 +1,83 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* max.cpp - Example program for finding maximum of a pair of values.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
double d1 = 10.0, d2 = 20.0;
//
// Find minimum.
//
double val1 = min(d1, d2);
//
// The greater comparator returns the greater of the two values.
//
double val2 = min(d1, d2, greater<double>());
//
// Find minimum.
//
double val3 = max(d1, d2);
//
// The less comparator returns the smaller of the two values.
// Note that, like every comparison in the STL, max is
// defined in terms of the < operator, so using less here
// is the same as using the max algorithm with a default
// comparator.
//
double val4 = max(d1, d2, less<double>());
cout << val1 << " " << val2 << " " << val3 << " " << val4 << endl;
return 0;
}

View file

@ -0,0 +1,87 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* max_elem.cpp - Example program for finding maximum value in a range.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[5] = {1,3,5,32,64};
//
// Set up vector.
//
vector<int,allocator<int> > v1(d1+0, d1+5);
//
// Find the largest element in the vector.
//
iterator it1 = max_element(v1.begin(), v1.end());
//
// Find the largest element in the range from
// the beginning of the vector to the 2nd to last.
//
iterator it2 = max_element(v1.begin(), v1.end()-1, less<int>());
//
// Find the smallest element.
//
iterator it3 = min_element(v1.begin(), v1.end());
//
// Find the smallest value in the range from
// the beginning of the vector plus 1 to the end.
//
iterator it4 = min_element(v1.begin()+1, v1.end(), less<int>());
cout << *it1 << " " << *it2 << " " << *it3 << " " << *it4 << endl;
return 0;
}

View file

@ -0,0 +1,136 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* memfunc.cpp - Example program for mem_fun and other member function
* pointer wrappers. See Class Reference Section.
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <vector>
#include <functional>
#include <algorithm>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
//
// Very large city class
//
class MegaPolis
{
public:
MegaPolis(char* s = 0 , float n = 0):cityName(s),population(n) {;}
// The following function cannot return void due to limitations in
// some current C++ implementations.
virtual size_t byPopulation()
{
cout<<cityName<<"(MegaPolis)"<<"\t\t\t"<<population<<endl;
return 0;
}
float population;
protected:
char* cityName;
};
//
// City and surrounding area class
//
class MetroPolis : public MegaPolis
{
public:
MetroPolis(char* s = 0 , float n = 0):MegaPolis(s,n){;}
virtual size_t byPopulation()
{
cout<<cityName<<"(MetroPolis)"<<"\t\t\t"<<population<<endl;
return 0;
}
};
//
// Functor compares the size of two MeagPolis classes
//
struct GreaterPopulation
{
bool operator()(MegaPolis* m1, MegaPolis* m2)
{
return m1->population<m2->population;
}
} greater_pop;
int main()
{
//
// Create a vector of very lareg cities
//
vector<MegaPolis*, allocator<MegaPolis*> > cityList;
cityList.push_back(new MegaPolis ("Calcutta",35));
cityList.push_back(new MegaPolis ("Tokyo",20));
cityList.push_back(new MegaPolis ("Delhi",10));
cityList.push_back(new MegaPolis ("Bombay",15));
cityList.push_back(new MetroPolis ("Cairo",5));
cityList.push_back(new MetroPolis ("New York",2.5));
cityList.push_back(new MetroPolis ("Los Angeles",3));
cityList.push_back(new MetroPolis ("Jakarta",1.5));
//
// Now use mem_fun to pass byPopulation member function
// of MegaPolis to the for_each function.
//
cout<<"City "<<" Population (in millions) "<<endl;
cout<<"----- "<<" -----------------------"<<endl;
for_each(cityList.begin(),cityList.end(),mem_fun(&MegaPolis::byPopulation));
cout<<"..............After sorting..........................."<<endl;
stable_sort(cityList.begin(),cityList.end(),greater_pop);
for_each(cityList.begin(),cityList.end(),mem_fun(&MegaPolis::byPopulation));
return 0;
}

View file

@ -0,0 +1,100 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* memfunref.cpp - Example program for mem_fun and other member function
* reference wrappers. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <list>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
template <class T> class subList
{
public:
//
//
int sort()
{
l.sort();
return 1;
}
subList(int * begin, int* end):l(begin,end){}
int display()
{
copy(l.begin(),l.end(),ostream_iterator<int,char,char_traits<char> >(cout," "));
cout<<endl;
return 1;
}
private:
list<T, allocator<T> > l;
};
int main()
{
int a1[] = {2,1,5,6,4};
int a2[] = {11,4,67,3,14};
subList<int> s1(a1,a1+5);
subList<int> s2(a2,a2+5);
// Build a list of subLists
list<subList<int>, allocator<subList<int> > > l;
l.insert(l.begin(),s1);
l.insert(l.begin(),s2);
// Sort each subList in the list
for_each(l.begin(),l.end(),mem_fun_ref(&subList<int>::sort));
// Display the contents of list
for_each(l.begin(),l.end(),mem_fun_ref(&subList<int>::display));
return 0;
}

View file

@ -0,0 +1,121 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* merge.cpp - Example program of merging sequences.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
int d1[4] = {1,2,3,4};
int d2[8] = {11,13,15,17,12,14,16,18};
//
// Set up two vectors.
//
vector<int,allocator<int> > v1(d1+0, d1+4), v2(d1+0, d1+4);
//
// Set up four destination vectors.
//
vector<int,allocator<int> > v3(d2+0, d2+8), v4(d2+0, d2+8), v5(d2+0, d2+8), v6(d2+0, d2+8);
//
// Set up one empty vector.
//
vector<int,allocator<int> > v7;
//
// Merge v1 with v2.
//
merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());
//
// Now use comparator.
//
merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v4.begin(), less<int>());
//
// In place merge v5.
//
vector<int,allocator<int> >::iterator mid = v5.begin();
advance(mid,4);
inplace_merge(v5.begin(),mid,v5.end());
//
// Now use a comparator on v6.
//
mid = v6.begin();
advance(mid,4);
inplace_merge(v6.begin(), mid, v6.end(), less<int>());
//
// Merge v1 and v2 to empty vector using insert iterator.
//
merge(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v7));
//
// Copy all cout.
//
ostream_iterator<int,char,char_traits<char> > out(cout," ");
copy(v1.begin(),v1.end(),out);
cout << endl;
copy(v2.begin(),v2.end(),out);
cout << endl;
copy(v3.begin(),v3.end(),out);
cout << endl;
copy(v4.begin(),v4.end(),out);
cout << endl;
copy(v5.begin(),v5.end(),out);
cout << endl;
copy(v6.begin(),v6.end(),out);
cout << endl;
copy(v7.begin(),v7.end(),out);
cout << endl;
//
// Merge v1 and v2 to cout.
//
merge(v1.begin(),v1.end(),v2.begin(),v2.end(),
ostream_iterator<int,char,char_traits<char> >(cout," "));
return 0;
}

View file

@ -0,0 +1,90 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* messages.cpp - Example program for the messages facet.
* See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <string>
#include <locale>
#include <iostream>
#include "rwstdmsg.h"
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
locale loc;
// Get a reference to the messages<char> facet
const messages<char>& mess =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<messages<char> >(loc);
#else
use_facet(loc,(messages<char>*)0);
#endif
// Open a catalog and try to grab
// both some valid messages, and an invalid message
string def("Message Not Found");
messages<char>::catalog cat =
#ifdef __WIN32__
mess.open("rwstdmsg.dll",loc);
#else
mess.open("./rwstdmsg.cat",loc);
#endif
if (cat != -1)
{
string msg0 = mess.get(cat,1,_RW_MSG_HELLO,def);
string msg1 = mess.get(cat,1,_RW_MSG_GOODBYE,def);
string msg2 = mess.get(cat,1,_RW_MSG_NOGOOD,def); // invalid msg #
string msg3 = mess.get(cat,2,_RW_MSG_TREES,def);
mess.close(cat);
cout << msg0 << endl << msg1 << endl
<< msg2 << endl << msg3 << endl;
}
else
cout << "Unable to open message catalog" << endl;
return 0;
}

View file

@ -0,0 +1,84 @@
#include "stlexam.h"
#pragma hdrstop
/**************************************************************************
*
* mismatch.cpp - Example program of comparing elements from two sequences
* and returning the first two elements that don't
* match each other. See Class Reference Section
*
***************************************************************************
*
* (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
* ALL RIGHTS RESERVED
*
* The software and information contained herein are proprietary to, and
* comprise valuable trade secrets of, Rogue Wave Software, Inc., which
* intends to preserve as trade secrets such software and information.
* This software is furnished pursuant to a written license agreement and
* may be used, copied, transmitted, and stored only in accordance with
* the terms of such license and with the inclusion of the above copyright
* notice. This software and information or any other copies thereof may
* not be provided or otherwise made available to any other person.
*
* Notwithstanding any other lease or license that may pertain to, or
* accompany the delivery of, this computer software and information, the
* rights of the Government regarding its use, reproduction and disclosure
* are as set forth in Section 52.227-19 of the FARS Computer
* Software-Restricted Rights clause.
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7013.
* Contractor/Manufacturer is Rogue Wave Software, Inc.,
* P.O. Box 2328, Corvallis, Oregon 97339.
*
* This computer software and information is distributed with "restricted
* rights." Use, duplication or disclosure is subject to restrictions as
* set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
* Computer Software-Restricted Rights (April 1985)." If the Clause at
* 18-52.227-74 "Rights in Data General" is specified in the contract,
* then the "Alternate III" clause applies.
*
**************************************************************************/
#include <algorithm>
#include <vector>
#include <functional>
#ifdef _RW_STD_IOSTREAM
#include <iostream>
#else
#include <iostream.h>
#endif
int main ()
{
#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif
typedef vector<int,allocator<int> >::iterator iterator;
int d1[4] = {1,2,3,4};
int d2[4] = {1,3,2,4};
//
// Set up two vectors.
//
vector<int,allocator<int> > vi1(d1+0, d1+4), vi2(d2+0, d2+4);
//
// p1 will contain two iterators that point to the first pair of
// elements that are different between the two vectors.
//
pair<iterator, iterator> p1 = mismatch(vi1.begin(), vi1.end(), vi2.begin());
//
// Find the first two elements such that an element in the
// first vector is greater than the element in the second vector.
//
pair<iterator, iterator> p2 = mismatch(vi1.begin(), vi1.end(),
vi2.begin(), less_equal<int>());
//
// Output results.
//
cout << *p1.first << ", " << *p1.second << endl;
cout << *p2.first << ", " << *p2.second << endl;
return 0;
}

Some files were not shown because too many files have changed in this diff Show more