Implementing any_of in C++ I've decided to implement Python's any in C++. I've gone about this using templates to allow multiple types of data to be passed, instead of overloading the function multiple times. This is my first time using templates so I would really like feedback about my usage of them. I'm also fairly new with references and pointers, so I would like some criticism about my use of them as well. Of course, anything else is on the table and appreciated.

While writing this program, I realized std::any_of existed. So yes, I do know there's already a built-in method for this.

any.hpp

#ifndef ANY_HPP_INCLUDED
#define ANY_HPP_INCLUDED

/**
 * @author Ben Antonellis
**/

#include &lt;vector&gt;
#include &lt;iostream&gt;

/**
 * Returns True if any of the elements meet the callback functions parameters.
 * 
 * @param elements - A list of elements.
 * @param callback - Callback function to invoke on each element.
 * 
 * @return bool - True if parameters are met, False otherwise.
**/
template &lt;typename List, typename Function&gt;
bool any(List &amp;elements, Function *callback) {
    for (auto element : elements) {
        if (callback(element)) {
            return true;
        }
    }
    return false;
}

#endif


And here's how I'm testing this function:

main.cpp

/**
 * @author Ben Antonellis
**/

#include "Any.hpp"

int main() {

    std::vector&lt;double&gt; doubleElements = {-1.0, -2.0, -3.0};
    std::vector&lt;std::string&gt; stringElements = {"Hello", "Goodbye", "Testing 123"};

    auto doubleFunc = [] (double number) {
        return number &lt; 0;
    };
    auto stringFunc = [] (std::string string) {
        return string.length() &gt;= 5;
    };

    /* Test Any Implementation */
    if (any(doubleElements, *doubleFunc)) {
        std::cout &lt;&lt; "(any) Double Success." &lt;&lt; std::endl;
    }
    if (any(stringElements, *stringFunc)) {
        std::cout &lt;&lt; "(any) String Success." &lt;&lt; std::endl;
    }

    return 0;
}


If you would like to compile and run, below is the script I'm using to compile and run this program.

run.sh

# Compile c++ program to .o file #
g++ -std=gnu++2a -c main.cpp # gnu++2a = Working draft for ISO C++ 2020 with GNU extensions #

# Compile .o file to executable #
g++ main.o -o app

# Run the executable #
./app

# Delete executable and .o files after running #
rm app main.o
The algorithm looks correct.

Regarding the function signature, I'd make three changes:


You're not modifying elements, so take it by constant reference rather than reference.  
You don't need to specify a pointer to Function, Function is already a template parameter, and non-pointers could be valid (ex: a class with a () operator).   
"callback" isn't a very useful name for this case.  "predicate" would be better.   


While this form is fine, I'd also include a version that takes a start/end iterator instead of a container.

Also, there's no reason to include vector or iostream in any.hpp - only include things that are necessary.

For completeness in the testing method, you should also test with an empty collection, and a collection with no matches.