FBB::PtrIter(3bobcat)
πΈ FBB::PtrIter β straight out of the 3bobcat manual, aka "Iterator pointing to pointers" πΈ
okay bestie, sit down, hydrate, because this one is lowkey iconic π
NAME β¨
FBB::PtrIter β an iterator that hands you back a pointer the moment you dereference it. no cap π
SYNOPSIS π
#include <bobcat/ptriter>
DESCRIPTION π¦
The PtrIter class template is an input iterator, and its operator* returns the address of the element the iterator is pointing at. that's it, that's the whole vibe.
okay but let me paint you a picture, because this is where it gets good. imagine a std::unordered_map<std::string, DataType>. its begin member returns an iterator whose operator* gives you back a std::pair<std::string, DataType> (const) &. and normally? that's exactly what you want, no notes. but now imagine we wanna display that map's content sorted by its keys π
sorting can just be done by making a lil support vector stuffed with pointers to the elements in the map, and then sorting the strings those pointers point at. so clean.
PtrIter is literally the tool you use to build that support vector, and the EXAMPLE section down below shows you exactly how it eats. π
PtrIter is a class template that wants one template type parameter: Iterator, the iterator's type (think vector<string>::iterator, iykyk).
and here's the slay part: PtrIter's users don't have to spell out PtrIter's template type β¨. The function template ptrIter, when you hand it an iterator, returns the matching PtrIter object. free real estate.
NAMESPACE π
FBB
All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. periodt.
INHERITS FROM π
std::iterator<std::input_iterator_tag, ...>
FREE FUNCTION π«
PtrIter<Iterator> ptrIter(Iterator const &iter)β this function template returns aPtrIterobject for the function'sIteratorargument. This function template simplifies the construction of aPtrItersince no template parameters need to be specified (see also the EXAMPLE section). it's giving convenience, and we love her for it π«Ά
CONSTRUCTORS π
PtrIter(Iterator const &iter)β the iter parameter must be initialized with an existing input iterator, and that iterator has to offeroperator*,operator++,operator==andoperator!=. And becausePtrIteris a class template, its template type parameters must be specified when you define aPtrIterobject. E.g.,
PtrIter<set<string>::iterator> PtrIter(mySet.begin());
Copy and move constructors (and assignment operators) are available. yup, the whole set π
OVERLOADED OPERATORS β‘
PtrType operator*() constβ the address of the entity the iterator refers to is returned;PtrIter &operator++()β the iterator is (pre)incremented to the next position;bool operator==(PtrIter const &other) constβtrueis returned if the two iterators are equal;bool operator!=(PtrIter const &other) constβtrueis returned if the two iterators are unequal;
USING DECLARATION π
The PtrIter class template defines PtrType:
using PtrType = decltype(&*Iterator()):
MEMBER FUNCTIONS π§
All members of std::iterator<std:::input_iterator_tag, ...> are available, as FBB::PtrIter inherits from this class. bestie really said "everything my parent has is mine" π
EXAMPLE π»
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <cstring>
#include <iostream>
#include <bobcat/ptriter>
using namespace std;
using namespace FBB;
int main()
{
cout << "Enter lines, the first word will be the map's key; "
"^D when done.\n";
string key;
string line;
unordered_map<string, string> map;
while (cin >> key && getline(cin, line)) // fill the map
map[key] = line;
cout << '\n';
// initialize a support
vector<decltype(&*map.begin())> // vector, using ptrIter
support(ptrIter(map.begin()), ptrIter(map.end()));
// sort 'support'
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 << ' ' << element->second << '\n';
}
FILES π
bobcat/ptriter β defines the class interface
SEE ALSO π
BUGS π
None Reported. (not a single one, we're flawless π β¨)
BOBCAT PROJECT FILES π
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6β debian package containing the shared library, changelog and copyright note;libbobcat-devβ debian package containing the static library, headers, manual pages, and developer info;
BOBCAT πΎ
Bobcat is an acronym of Brokken's Own Base Classes And Templates. cute AND clever, obsessed.
COPYRIGHT βοΈ
This is free software, distributed under the terms of the GNU General Public License (GPL). share the love, bestie π«Ά
AUTHOR βοΈ
Frank B. Brokken (f.b.brokken@rug.nl).
and that's the whole page, no crumbs left π this was libbobcat-dev_6.15.01, dated 2005-2026, and it's the FBB::PtrIter(3bobcat) manual. go dereference something, you've got this ππΈ
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms