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 a PtrIter object for the function's Iterator argument. This function template simplifies the construction of a PtrIter since 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 offer operator*, operator++, operator== and operator!=. And because PtrIter is a class template, its template type parameters must be specified when you define a PtrIter object. 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 β€” true is returned if the two iterators are equal;
  • bool operator!=(PtrIter const &other) const β€” true is 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 πŸ‘€

bobcat(7)

BUGS πŸ’€

None Reported. (not a single one, we're flawless πŸ’…βœ¨)


BOBCAT PROJECT FILES 🌈

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.

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