- в следующем коде — это функция, которая используется только для целей «отладки». В моем рабочем проекте нет никакой реальной пользы.
Код: Выделить всё
test_container - Настоящая функция называется foreach (см. последний код в этом вопросе). )
- — это функция, которая возвращает std::string представление контейнера (после этого исправления я заставлю ее работать и с массивами int)
Код: Выделить всё
foreach - Даже представление foreach здесь минимизировано для лучшего понимания: здесь оно похоже на test_container, с небольшими отличиями.
Код: Выделить всё
#include
#include
#include
#include
#include
template
struct has_template_argument {
static const bool value = false;
};
// Specialization of a template for types with template arguments
template
struct has_template_argument {
static const bool value =
!std::is_same::value;
};
// Function to verify if the variable has a template argument
template
bool has_template_arg(const T&) {
return has_template_argument::value;
}
// The test collection funtion.
template
std::string test_container(const T& container) {
std::stringstream listn;
listn
Подробнее здесь: [url]https://stackoverflow.com/questions/78254547/why-the-function-recursion-seems-to-make-the-conditions-works-crazily[/url]