Код: Выделить всё
#include
#include
#include
#include
// Define dummy attribute types
namespace Attr {
struct Int {};
struct Float {};
struct String {};
// TypeMap must be defined before being used
template struct TypeMap; // Primary template
// Specializations
template struct TypeMap { using type = int; };
template struct TypeMap { using type = float; };
template struct TypeMap { using type = std::string; };
}
// Define AttrTypes
template
struct AttrTypes {};
template
std::vector allowed_types() {
return { std::type_index(typeid(typename Attr::TypeMap::type))... };
}
// Single type version
template >
void addInput(Args&&... args) {
// Leave it as is. It's here to test if both addInput are working.
//std::vector allowedTypes = {std::type_index(typeid(typename Attr::TypeMap::type))};
std::cout
< /blockquote>
Есть две версии AddInput < /code> < /p>
PrettyPrint-Override ">addInput("a");
Вторая версия AddInput :
Код: Выделить всё
using Allowed = AttrTypes;
addInput("b");
< /code>
Это следует использовать только в списке attrtypes < /code>, который следует преобразовать
в вектор < /code> внутри функции. < /p>
Во -вторых, как мы можем добавить тест, чтобы проверить обе функции, которые должны быть поддержаны, и есть поддержание, и есть поддержание. должен проверить, доступен ли тип: < /p>
alltypes = {Attr::Int, Attr::Float, Attr::String}
На для нескольких типов мы должны повторить и проверить все типы.
Подробнее здесь: https://stackoverflow.com/questions/796 ... uous-error