IVec with HTArray

This commit is contained in:
Joachim Schoeberl 2024-07-16 19:20:07 +02:00
parent e075d32f14
commit b6b20be30b
2 changed files with 41 additions and 12 deletions

View File

@ -1528,6 +1528,8 @@ namespace ngcore
}
struct HTAHelp { };
// head-tail array
template <size_t S, typename T>
class HTArray
@ -1535,10 +1537,22 @@ namespace ngcore
HTArray<S-1,T> tail;
T head;
public:
HTArray () = default;
HTArray (const HTArray &) = default;
constexpr HTArray () = default;
constexpr HTArray (const HTArray &) = default;
template <typename T2>
HTArray (const HTArray<S,T2> & a2) : tail(a2.Tail()), head(a2.Head()) { ; }
constexpr HTArray (const HTArray<S,T2> & a2) : tail(a2.Tail()), head(a2.Head()) { ; }
constexpr HTArray (T v) : tail(v), head(v) { } // all the same
template <class... T2,
std::enable_if_t<S==1+sizeof...(T2),bool> = true>
constexpr HTArray (const T &v, T2... rest)
: tail{HTAHelp(), v,rest...}, head(std::get<S-2>(std::tuple(rest...))) { }
template <class... T2>
constexpr HTArray (HTAHelp h, const T &v, T2... rest)
: tail{h, v,rest...}, head(std::get<S-2>(std::tuple(rest...))) { }
HTArray & operator= (const HTArray &) = default;
@ -1559,10 +1573,15 @@ namespace ngcore
{
T head;
public:
HTArray () = default;
HTArray (const HTArray &) = default;
constexpr HTArray () = default;
constexpr HTArray (const HTArray &) = default;
template <typename T2>
HTArray (const HTArray<1,T2> & a2) : head(a2.Head()) { ; }
constexpr HTArray (const HTArray<1,T2> & a2) : head(a2.Head()) { ; }
constexpr HTArray (T v) : head(v) { } // all the same
template <class... T2>
constexpr HTArray (HTAHelp h, const T &v, T2... rest)
: head(v) { }
HTArray & operator= (const HTArray &) = default;
@ -1590,7 +1609,7 @@ namespace ngcore
HTArray (const HTArray &) = default;
template <typename T2>
HTArray (const HTArray<0,T2> & a2) { ; }
constexpr HTArray (T v) { } // all the same
HTArray & operator= (const HTArray &) = default;
/*

View File

@ -46,13 +46,22 @@ namespace ngcore
class IVec
{
/// data
T i[(N>0)?N:1];
// std::array<T,N> i;
// T i[(N>0)?N:1];
HTArray<N,T> i;
public:
///
NETGEN_INLINE IVec () { }
constexpr NETGEN_INLINE IVec (T ai1) : i(ai1) { }
template <class... T2,
std::enable_if_t<N==1+sizeof...(T2),bool> = true>
constexpr IVec (const T &v, T2... rest)
: i{v,rest...} { }
/*
/// init all
NETGEN_INLINE IVec (T ai1)
{
@ -78,12 +87,13 @@ namespace ngcore
/// init i[0], i[1], i[2]
NETGEN_INLINE IVec (T ai1, T ai2, T ai3, T ai4, T ai5, T ai6, T ai7, T ai8, T ai9)
: i{ai1, ai2, ai3, ai4, ai5, ai6, ai7, ai8, ai9 } { ; }
*/
template <typename ARCHIVE>
void DoArchive(ARCHIVE& ar)
{
// ar.Do(i.begin(), N);
ar.Do(i, N);
ar.Do(i.Ptr(), N);
}
template <int N2, typename T2>