#include <array>
//#include <initializer_list>
#include <algorithm>
template<class T,std::size_t N>
class ConstexprVector {
T Buff[N]{};
std::size_t C = 0;
public:
typedef T ValueType;
typedef T* Iterator;
typedef T const* ConstIterator;
constexpr ConstexprVector(){};
constexpr explicit ConstexprVector(const std::initializer_list<T>& L) {
std::size_t V = 0;
auto it1 = L.begin();
auto it2 = &Buff[0];
for (it1, it2; L.end() != it1&&it2 != &Buff[N]; it1++, it2++) {
*it2 = *it1;
V++;
}
C = V;
}
template<class Iter>
constexpr explicit ConstexprVector(Iter Beg,Iter End) {
std::size_t V = 0;
auto it1 = Beg;
auto it2 = &Buff[0];
for (it1, it2; End != it1&&it2 != &Buff[N]; it1++, it2++) {
*it2 = *it1;
V++;
}
C = V;
}
constexpr std::size_t Size() const{
return C;
}
constexpr std::size_t MaxSize() const {
return N;
}
constexpr bool PushBack(const T& In) {
if (C >= N) return false;
Buff[C] = In;
C++;
return true;
}
/** /
template<class... A>
constexpr bool EmplaceBack(const A& ...In) {
if (C >= Buff.size()) return false;
Buff[C] = T(In...);
C++;
return true;
}
/**/
constexpr bool PopBack() {
if (C == 0)return false;
//Buff[C]~T();
C--;
return true;
}
constexpr bool Clear() {
while (PopBack());
return true;
}
constexpr Iterator begin() {
return Buff;
}
constexpr ConstIterator begin() const {
return &Buff[0];
}
constexpr Iterator end() {
return Buff+C;
}
constexpr ConstIterator end() const {
return Buff+C;
}
constexpr T& operator[](std::size_t idx) {
int A = 0;
if (Size() <= idx) A = 1/A;//kill?
return Buff[idx];
}
constexpr const T& operator[](std::size_t idx) const {
int A = 0;
if (Size() <= idx) A = 1/A;//kill?
return Buff[idx];
}
};
#include <iostream>
#include <cstdint>
//#include "ConstexprVector.h"
typedef ConstexprVector<std::uint64_t, 128> DType;
constexpr std::uint64_t Calc2(const DType& D) {
std::uint64_t C = 0;
for (auto& o:D) {
C += o;
}
return C;
}
constexpr std::uint64_t Calc(const DType& D) {
std::uint64_t C = 0;
for (std::size_t i = 0; i < D.Size();i++) {
C += D[i];
}
return C;
}
constexpr DType Add(const DType& D, DType::ValueType V) {
DType R(D.begin(), D.end());
R.PushBack(V);
return R;
}
int main() {
constexpr DType D{ 1,2,3,4,5 };
constexpr std::uint64_t R = Calc(D);
constexpr std::uint64_t R2 = Calc2(D);
constexpr DType D2= Add(D, 6);
constexpr std::uint64_t R3 = Calc(D2);
std::cout << R << std::endl;
std::cout << R3 << std::endl;
return true;
}