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:
- stdx::set_pair_open - Set pair opening bracket character
- stdx::set_pair_delim - Set delimiter character between pair elements
- stdx::set_pair_close - Set pair closing bracket character
- stdx::set_pair_tuple - Set pair format to a "<first,second>" format
- stdx::set_pair_nameval - Set pair format to a "first=second" format
- 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
- struct stdx::select1st
- Select first element of a pair.
- Select first element of a pair.
- class stdx::AlignedNameValuePairs
- Simplifies printing aligned name/value pairs.
- Simplifies printing aligned name/value pairs.
- class stdx::set_pair_delim
- IO Manip: Sets the delimiter to use between pair elements.
- IO Manip: Sets the delimiter to use between pair elements.
- class stdx::set_pair_open
- IO Manip: Sets character to use at the front of pairs.
- IO Manip: Sets character to use at the front of pairs.
- class stdx::set_pair_close
- IO Manip: Sets character to use at the end of pairs.
- IO Manip: Sets character to use at the end of pairs.
Functions
- operator<< (std::ostream &os, const AlignedNameValuePairs &pairSeq)
- operator<< (std::ostream &os, const set_pair_delim &delimmanip)
- operator<< (std::ostream &os, const set_pair_open &delimmanip)
- operator<< (std::ostream &os, const set_pair_close &delimmanip)
- set_pair_tuple (std::ios_base &strm)
- set_pair_nameval (std::ios_base &strm)
- alignedPairsWriter (In itr1, In itr2, std::ostream &os, const std::string &separator=DEFAULT_ALIGNED_PAIR_SEP)
- alignedPairsWriter (In itr1, In itr2, const std::string &separator=DEFAULT_ALIGNED_PAIR_SEP)
- alignedPairsWriter (stdx::Iseq< In > in, std::ostream &os, const std::string &separator=DEFAULT_ALIGNED_PAIR_SEP)
- alignedPairsWriter (stdx::Iseq< In > in, const std::string &separator=DEFAULT_ALIGNED_PAIR_SEP)