Please consider the following example (tag manager, variation template, perfect redirection, etc., all in one):
#include <iostream>
#include <utility>
#include <string>
struct A { };
struct B { };
void doIt(A&&, const std::string &) {
std::cout << "A-spec" << std::endl;
}
template<typename T, typename... Args>
void doIt(T&&, Args&&...) {
std::cout << "template" << std::endl;
}
template<typename T, typename... Args>
void fn(Args&&... args) {
doIt(T{}, std::forward<Args>(args)...);
}
int main() {
const std::string foo = "foo";
std::string bar = "bar";
fn<A>(foo);
fn<A>(bar);
fn<B>(foo);
}
In this case, the output is:
A-spec
template
template
The reason is quite obvious, it does not bother me.
What I would like to achieve is to call the first instance of the function doItin both cases, regardless of whether the string has a const specifier or not.
Of course, a possible solution is to define a new one doItwith the right prototype, in any case, I would like to know if there is another solution.
add_const, , - .
, const ?
, .
, , , , std::string. , ( ) A int const std::string &, B float, C ...
- , , - std::string, , .