Unten sind zwei weitgehend identische Vorlagen PgmArray
und PgmArrayF
. Der erste arbeitet für lvalue-ref Template-Parameter, der zweite arbeitet für integrale Parameter. Ich möchte diese beiden zu einem kombinieren:Kombinieren Sie zwei fast identische Klassenvorlagen
#include <stdint.h>
#include <type_traits>
#include <array>
#include <iostream>
template<typename T, const T&... Ts>
struct PgmArray final {
static constexpr uint8_t size = sizeof... (Ts);
static constexpr T data[] {Ts...};
};
template<typename T, T... Ts>
struct PgmArrayF final {
static constexpr uint8_t size = sizeof... (Ts);
static constexpr T data[] {Ts...};
};
struct A{
uint8_t m = 0;
};
constexpr A a1{1};
constexpr A a2{2};
constexpr auto x1 = PgmArray<A, a1, a2>{}; // ok
constexpr auto x2 = PgmArrayF<int, 1, 2>{}; // ok
//constexpr auto x3 = PgmArrayF<A, a1, a2>{}; // nok
//constexpr auto x4 = PgmArray<int, 1, 2>{}; // nok
int main() {
}
Ausgezeichnet! Leider erzeugt dies ICE mit g ++> = 8.0 (g ++ 7.1 ist in Ordnung). – wimalopaan