/** * Copyright (c) 2026 Alexey Gavrilov * * This file is part of ObjectiveOS. * * ObjectiveOS is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * ObjectiveOS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * ObjectiveOS. If not, see . */ #ifndef CONTAINERSTUPLE_H #define CONTAINERSTUPLE_H #include template class Tuple : public Tuple { private: using valueType = Head; valueType value; public: using baseType = Tuple; Tuple(Head val_, Tail ... args) : baseType(args ...), value(val_) {}; static constexpr unsigned int length() {return sizeof...(Tail) + 1;} valueType getValue() {return value;}; template auto get() { using returnType = cut::process::result; return static_cast(*this); }; /* Create the class/struct before using the method F is this class/struct to pass in method trought template argument. F must contain a static method/s named "perform" that will perform something action for every value in tuple object. F must contain as many implementations as there are different types in the template F::perform() for the first argument accept tuple value, next arguments optional */ template void foreach(T ... arg) { if constexpr(If != NULL) { foreach(arg ...); } else { (F::perform(get().getValue(), arg ...)); (F::perform(get().getValue(), arg ...), ...); } }; }; template<> class Tuple<> { public: static constexpr unsigned int length() {return 0;} }; template class Tuple { private: using valueType = Head; valueType value; public: using baseType = Tuple<>; Tuple(Head val_) : value(val_) {}; Tuple() : value(valueType()) {}; static constexpr unsigned int length() {return 1;} valueType getValue() {return value;}; template auto get() { if constexpr (indx == NULL) return *this; else static_assert(!indx, "Tuple::get: Out of bounds"); }; /* Create the class/struct before using the method F is this class/struct to pass in method trought template argument. F must contain a static method/s named "perform" that will perform something action for every value in tuple object. F must contain as many implementations as there are different types in the template F::perform() for the first argument accept tuple value, next arguments optional */ template void foreach(T ... arg) { F::perform(value, arg ...); }; }; #endif