I am relatively new to C++ coming from a Java background so I am not sure if the functionality I am looking for is directly possible.
I am attempting to create a C++ function that accepts two different parameters but with the following requirements: The first parameter is a single input object of a specific type and the second parameter is a variable list of additional objects all of the which are the same type as the first parameter.
I am specifically looking for something similar to this Java code (if possible).
public static <E> boolean func(E input, E... args) {}
If this is not possible, does anyone know of some sort of implementation to make this to work for strings specifically? Something along the lines of:
bool func(std::string input, std::string... args) {}
I have researched this topic a bit and found that function templates might be able to help here, but I am unsure on how to support multiple parameter types (of the same datatype) using this approach.
My initial line of thinking was to try something like this:
template<class... T>
bool func(const T input, const T&... args) {}
But this only accounts for the varargs parameter type, not the first parameter.
Any help/advice is greatly appreciated. Thanks in advance.
template <typename T> bool func(std::initializer_list<T>);
. (requires extra{}
at call site). (seestd::max
(3/4) as example). – Gamber