Код: Выделить всё
(35): error C2752: 'Power_t': more than one partial specialization matches the template argument list
(18): note: could be 'Power_t'
(30): note: or 'Power_t'
(35): note: the template instantiation context (the oldest one first) is
(37): note: see reference to variable template 'const auto Power_v' being compiled
Код: Выделить всё
#include
#include // size_t
template
concept Multipliable = requires (T a, const T b) {
{ a *= b } -> std::same_as;
{ a * b } -> std::same_as;
};
/// Primary class template declaration (and definition) for odd powers (inductive step)
template
struct Power_t {
static constexpr auto value = Power_t::value * base;
};
/// Partial specialization for even powers (inductive step)
template
struct Power_t {
static constexpr auto value = Power_t::value;
};
/// Partial specialization (base case)
template
struct Power_t {
static constexpr auto value = base;
};
/// Partial specialization (base case)
template
struct Power_t {
static constexpr auto value = decltype(base){1};
};
template
constexpr auto Power_v = Power_t::value;
static_assert(Power_v == 1);
static_assert(Power_v == 3);
static_assert(Power_v == 3 * 3);
static_assert(Power_v == 3 * 3 * 3);
static_assert(Power_v == 3 * 3 * 3 * 3);
static_assert(Power_v == 3 * 3 * 3 * 3 * 3);
int main() {
return Power_v;
}
Интересно, что все компиляторы завершаются успешно, когда концептуальные ограничения удалены:
https://godbolt.org/z/MzYG9n5bP
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-argument