Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created July 17, 2025 04:32
Show Gist options
  • Save ParadoxV5/bae9c392b3e46fe8c991078640a91387 to your computer and use it in GitHub Desktop.
Save ParadoxV5/bae9c392b3e46fe8c991078640a91387 to your computer and use it in GitHub Desktop.
C++ Compile-time Fixed-Size Array of Types
#include <cstdint>
#include <tuple>
#include <type_traits>
#include <iostream>
using std::size_t;
/** Compile-time Fixed-Size Array of Types */
template<typename... T> struct TypeArray {
using TupleType = std::tuple<T...>;
template<size_t i> using At =
typename std::tuple_element<i, TupleType>::type;
};
/** Example array */
using MyArray = TypeArray<float, const uint64_t, std::string>;
/** Example fetch */
using TypeFromArray = MyArray::At<1>;
/** Verify */
static constexpr bool same = std::is_same<TypeFromArray, const uint64_t>::value;
int main() {
if(!same)
std::cout << "not ";
std::cout << "same" << std::endl;
return !same;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment