FBB::repeat(3bobcat)

πŸ’– FBB::repeat(3bobcat) β€” repeated function calls πŸ’–

okay bestie, come SIT. this is the bobcat manual, section 3bobcat, and today we're talking about FBB::repeat πŸŽ€ it's a lil function template that lives in the Bobcat library and it literally just calls your function a bunch of times. that's it. that's the whole vibe. ✨


🌸 NAME 🌸

FBB::repeat β€” call a (member) function a fixed number of times πŸ’…


🌈 SYNOPSIS 🌈

#include <bobcat/repeat>

✨ DESCRIPTION ✨

so the FBB::repeat function template lets you call a function β€” or a member function β€” a certain number of times. no loops written by hand, no counting on your fingers, just vibes πŸ¦‹

your functions (or member functions) are allowed to have arguments, and when you call repeat you pass those arguments in, and repeat perfectly forwards them straight to the (member) function that repeat ends up calling. perfect forwarding? yeah. she's doing it. no extra copies, no drama. πŸ’…

the first argument of the repeat function template is the one that says how many times the (member) function has to be called. that's it, that's the counter. πŸ”’

and the tea β˜• : the FBB::repeat function template is defined inline, which means the compiler is allowed to literally optimize away the repeat function call itself. iconic. the whole thing just evaporates into your code like it was never there. ✨


🫢 NAMESPACE 🫢

FBB

every single constructor, member, operator and manipulator mentioned in this man-page lives in the namespace FBB. periodt. πŸ‘‘


🧚 INHERITS FROM 🧚

-

(yeah. nothing. she inherits from nobody. she's self-made. main character energy fr fr πŸ’œ)


πŸ‘‘ REPEAT FUNCTION TEMPLATE πŸ‘‘

the repeat function template is declared like this:

template <typename Counter, typename First, typename ...Params>
void repeat(Counter counter, First &&first, Params &&...params);

and in that declaration, lemme break it all the way down:

  • Counter is the type of the counter. usually it's an int or a size_t πŸ’– when you call repeat, counter must be initialized to the number of times repeat has to call the (member) function (see below πŸ‘€).
  • First is the prototype of a function, or the name of a class. so first is either the address (the name) of the function you want called, or the name of an object of class type First. and in that second case β€” the object one β€” the object may or may not be a const object. no judgement either way. πŸ™ˆ
  • ...Params is the set of parameter types of the arguments that have to be perfectly forwarded to the function being called. and heads up bestie: if first is an object of a class type, then the first argument you pass must be the address of a member function of the class First. πŸŽ€

πŸ“ EXAMPLES πŸ“

this is the whole thing, verbatim, go off:

#include <iostream>
#include <iterator>
#include <algorithm>

#include <bobcat/repeat>

using namespace std;
using namespace FBB;

class Object
{
    public:
        void member(int argc, char **argv) const;
        void member2(size_t &rept, int argc, char **argv);
};

void Object::member(int argc, char **argv) const
{
    cout << "member called\n";
    copy(argv, argv + argc, ostream_iterator<char const *>(cout, "\n"));
}

void Object::member2(size_t &rept, int argc, char **argv)
{
    cout << "member2 called, iteration " << rept++ << "\n";
    copy(argv, argv + argc, ostream_iterator<char const *>(cout, "\n"));
}

void fun()
{
    cout << "Fun called\n";
}

int main(int argc, char **argv)
{
    Object object;

    cout << "\n"
            "*** The number of arguments determines the repeat-count ***\n\n";

    cout << "Fun without arguments:\n";
    repeat(argc, fun);

    cout << "Object receiving argc and argv:\n";
    repeat(argc, object, &Object::member, argc, argv);

    cout << "Object receiving argc and argv, showing the iteration count:\n";
    size_t count = 0;
    repeat(argc, object, &Object::member2, count, argc, argv);

    Object const obj;
    cout << "Const Object receiving argc and argv:\n";
    repeat(argc, obj, &Object::member, argc, argv);

}

πŸŽ€ FILES πŸŽ€

  • bobcat/repeat β€” defines the class interface πŸ’–

πŸ”₯ SEE ALSO πŸ”₯


πŸ’€ BUGS πŸ’€

okay so listen, because this one matters: be careful when using overloaded functions. the template argument resolution mechanism may straight up be unable to figure out which function it's supposed to call 😭 that's not a vibe, that's a compile error.

and if you must use overloaded functions? you're probably gonna need a static_cast to disambiguate your intentions. yes bestie, you have to spell it out for the compiler. she's smart but she's not a mind reader. πŸ™ˆ


🌟 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 right?? it's a backronym and it ATE. πŸ’…


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


⭐ AUTHOR ⭐

Frank B. Brokken (f.b.brokken@rug.nl). thank you for your service king πŸ‘‘


and that's the whole page bestie!! ✨ this was libbobcat-dev_6.15.01, dated 2005-2026, and yes she's been serving for two decades and still looks this good. no cap. now go call your functions a fixed number of times the fancy way πŸŽ€πŸ’–πŸ¦‹

πŸ“¦ where this page comes from