C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdxPairs.h Classes and Functions

Functions and classes to help with input/output of the std::pair class. Includes various io manipulators to set the open, close, and delimiter characters for pairs. There are also two preset formats: tuple and namevar. These formats can be enabled with the set_pair_tuple and set_pair_nameval IO manipulators and are essentially just shorthand for setting the open, close, and delimiter character in one step. In combination with the Iseq insertion operator you can do the following:

 map<string,int> testmap;
 testmap["one"]   = 1;
 testmap["two"]   = 2;
 testmap["three"] = 3;
 testmap["four"]  = 4;

 cout << iseq(testmap) << endl;
 cout << set_pair_open('[') << set_pair_close(']') << iseq(testmap) << endl;
 cout << set_pair_nameval << iseq(testmap) << endl;

This code will produce the following output:

 <one,1>, <two,2>, <three,3>, <four,4>
 [one,1], [two,2], [three,3], [four,4]
 one=1, two=2, three=3, four=4
 

One can also make use of the aligned pair writers to vertically align a sequence of pairs. A list of the IO manipulators suitable for use with outputing pairs to streams is below:

Todo:
Add an extraction operator for pairs. It may not always work - for example if someone uses the close char in the actual element string, but it should work for some cases.

Compounds

Functions

Aligned Pair Sequence Writer

Detailed Documentation

Function Documentation

template<class In>
void alignedPairsWriter In    itr1,
In    itr2,
std::ostream &    os,
const std::string &    separator = DEFAULT_ALIGNED_PAIR_SEP
 

A string writer function which takes an input sequence of pairs and outputs each pair one a new line with a separator between pair.first and pair.second. The function makes sure that all the pair.seconds are vertically aligned. An example is below:

 map<string,int> testMap;
 testMap["Number of states"]          = 50;
 testMap["Number of original states"] = 13;
 testMap["A baker's dozen"]           = 13;
 testMap["The answer to everything"]  = 42;
 testMap["Lucky number"]              = 7;
 cout << alignedPairsWriter(stdx::iseq(testMap));

This results in the following output:

 Number of states          : 50
 Number of original states : 13
 A baker's dozen           : 13
 The answer to everything  : 42
 Lucky number              : 7
 

std::ostream& operator<< std::ostream &    os,
const AlignedNameValuePairs   pairSeq
 

Insertion operator for aligned name value pair objects

std::ostream& operator<< std::ostream &    os,
const set_pair_delim   delimmanip
 

Insertion operator for the set_pair_delim io manipulator

std::ostream& operator<< std::ostream &    os,
const set_pair_open   delimmanip
 

Insertion operator for the set_pair_open io manipulator

std::ostream& operator<< std::ostream &    os,
const set_pair_close   delimmanip
 

Insertion operator for the set_pair_close io manipulator

std::ios_base& set_pair_tuple std::ios_base &    strm
 

An IO manipluator which enables the tuple preset pair format. This format prints pairs in the form: <first,second>

std::ios_base& set_pair_nameval std::ios_base &    strm
 

An IO manipluator which enables the nameval preset pair format. This format is useful for pairs which represent name/value pairs and it prints pairs in the form: first=second

template<class In>
std::string alignedPairsWriter In    itr1,
In    itr2,
const std::string &    separator = DEFAULT_ALIGNED_PAIR_SEP
 

Overloaded version of stdx::alignedPairsWriter which returns a string and thus makes it more convenient to directly insert a aligned pair sequence into a stream.

template<class In>
void alignedPairsWriter stdx::Iseq< In >    in,
std::ostream &    os,
const std::string &    separator = DEFAULT_ALIGNED_PAIR_SEP
 

Overloaded version of stdx::alignedPairsWriter which takes an explicit input sequence as input instead of two iterators.

template<class In>
std::string alignedPairsWriter stdx::Iseq< In >    in,
const std::string &    separator = DEFAULT_ALIGNED_PAIR_SEP
 

Overloaded version of stdx::alignedPairsWriter which takes an explicit input sequence as input instead of two iterators and returns a string.

Generated on Mon Aug 15 21:43:09 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002