GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PTRITER (3)

NAME

FBB::PtrIter - Iterator returning pointer when dereferenced

CONTENTS

SYNOPSIS

#include <bobcat/ptriter>

DESCRIPTION

The PtrIter class template implements an input iterator whose operator* returns the address of the element the iterator refers to. Consider a std::unordered_map<std::string, DataType>. Its begin member returns an iterator whose operator* returns a std::pair<std::string, DataType> (const) &. This is usually what you want, but now assume we want to display the map\(cqs contents, sorted by its keys. Sorting can simply be performed by defining a support vector containing pointers to the elements in the map, and then sorting the strings the pointers point at.

PtrIter is a tool that can be used to construct such a support vector, as shown in the EXAMPLE section.

PtrIter is a class template requiring one template type parameter: Iterator, the iterator\(cqs type (e.g., vector<string>::iterator)

PtrIter\(cqs users don\(cqt have to specify PtrIter\(cqs template type. The function template ptrIter, when provided with an iterator returns the matching PtrIter object.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

std::iterator<std::input_iterator_tag, ...>

FREE FUNCTION

o PtrIter<Iterator> ptrIter(Iterator const &iter):
this function template returns a PtrIter object for the function\(cqs Iterator argument. This function template simplyfies the construction of a PtrIter as no template parameters need to be specified (see also the EXAMPLE section)

CONSTRUCTORS

o PtrIter(Iterator const &iter):
The iter parameter must be initialized with an existing input iterator, offering operator*, operator++, operator== and operator!=. As PtrIter is a class template, its template type parameters must be specified when defining a PtrIter object. E.g.,

PtrIter<set<string>::iterator> PtrIter(mySet.begin());

The copy and move constructors are available.

OVERLOADED OPERATORS

o PtrType operator*() const:
the address of the entity the iterator refers to is returned;
o PtrIter &operator++():
the iterator is (pre)incremented to the next position;
o bool operator==(PtrIter const &other) const:
true is returned if the two iterators are equal;
o bool operator!=(PtrIter const &other) const:
true is returned if the two iterators are unequal; The copy and move assignment operators are available.

DEFINED TYPE

PtrIter defines the following type:
o typedef decltype(&*Iterator()) PtrType:

MEMBER FUNCTIONS

All members of std::iterator<std:::input_iterator_tag, ...> are available, as FBB::PtrIter inherits from this class.

EXAMPLE

#include <algorithm>
#include <unordered_map>
#include <vector>
#include <cstring>
#include <iostream>

#include <bobcat/ptriter>

using namespace std; using namespace FBB;

int main() { cout << \(dqEnter lines, the first word will be the map\(cqs key; \(dq \(dq^D when done.\n\(dq;

string key; string line; unordered_map<string, string> map; while (cin >> key && getline(cin, line)) // fill the map map[key] = line; cout << \(cq\n\(cq;

// initialize a support vector<decltype(&*map.begin())> // vector, using ptrIter support(ptrIter(map.begin()), ptrIter(map.end()));

// sort \(cqsupport\(cq typedef unordered_map<string, string>::value_type VT; sort(support.begin(), support.end(), [&](VT const *p1, VT const *p2) { return strcasecmp(p1->first.c_str(), p2->first.c_str()) < 0; } );

for(auto &element: support) // display sorted by key cout << element->first << \(cq \(cq << element->second << \(cq\n\(cq; }

FILES

bobcat/ptriter - defines the class interface

SEE ALSO

bobcat(7)

BUGS

None Reported.

DISTRIBUTION FILES

o bobcat_3.25.01-x.dsc: detached signature;
o bobcat_3.25.01-x.tar.gz: source archive;
o bobcat_3.25.01-x_i386.changes: change log;
o libbobcat1_3.25.01-x_*.deb: debian package holding the libraries;
o libbobcat1-dev_3.25.01-x_*.deb: debian package holding the libraries, headers and manual pages;
o http://sourceforge.net/projects/bobcat: public archive location;

BOBCAT

Bobcat is an acronym of ‘Brokken\(cqs Own Base Classes And Templates\(cq.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).

Search for    or go to Top of page |  Section 3 |  Main Index


libbobcat-dev_3&.25&.01-x&.tar&.gz FBB::PTRITER (3bobcat) 2005-2015

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.