Сначала а вообще хочу сказать огромное спасибо автору. Задачи были довольно интересными, сложными и увлекательными.
Одна часть задачи вызвала у меня некоторые проблемы, и я не совсем понимаю, почему.
< pre class="lang-cpp Prettyprint-override">
Код: Выделить всё
/**
* 18. Define Insert for Vector, it should take position, value and vector.
* Don't worry about bounds.
* Hint: use the enable_if trick, e.g.
* template struct Foo;
* template struct Foo {...};
* template struct Foo {...};
*/
// Your code goes here:
// ^ Your code goes here
// static_assert(std::is_same_v);
// static_assert(std::is_same_v);
// static_assert(std::is_same_v);
// static_assert(std::is_same_v);
Это была моя первая попытка.
Код: Выделить всё
template struct Insert;
template struct Insert {
using type = Prepend::type;
};
template struct Insert {
using type = typename Prepend::type;
};
Код: Выделить всё
E:\problems\main.cpp(212,20): error: ambiguous partial specializations of 'Insert'
[build] 212 | std::is_same_v);
[build] | ^
[build] E:\problems\main.cpp(163,49): note: partial specialization matches [with P = 0, I = 3, F = 4, N = ]
[build] 163 | template struct Insert
> {
[build] | ^
[build] E:\problems\main.cpp(167,35): note: partial specialization matches [with I = 3, N = ]
[build] 167 | template struct Insert
Код: Выделить всё
template struct Insert;
template struct Insert {
using type = std::conditional_t<
P == 0, typename Prepend::type,
typename Prepend::type>;
};
Код: Выделить всё
[build] E:\problems\main.cpp(178,36): error: implicit instantiation of undefined template '(anonymous namespace)::Insert'
[build] 178 | typename Prepend::type>::type>;
[build] | ^
[build] E:\problems\main.cpp(178,36): note: in instantiation of template class '(anonymous namespace)::Insert' requested here
[build] E:\problems\main.cpp(178,36): note: in instantiation of template class '(anonymous namespace)::Insert' requested here
[build] E:\problems\main.cpp(222,20): note: in instantiation of template class '(anonymous namespace)::Insert' requested here
[build] 222 | std::is_same_v);
[build] | ^
[build] E:\problems\main.cpp(173,44): note: template is declared here
[build] 173 | template struct Insert;
[build] | ^
Подробнее здесь: https://stackoverflow.com/questions/790 ... resolution