Best way to implement fixed size array in C++

I am trying to implement a fixed size array of 32 bit integers, but the size is determined at runtime so it has to be heap allocated. Would it be more efficient to use a c++ std::vector and use vector.reserve() or should I use the conventional way of doing it using new int32_t[size]? Additionally, would… Read More Best way to implement fixed size array in C++

C++ variadic template: typeid of it, way to optimize

So, I learn variadic templates and usage of it. Now I made that code below. The question is does some other methode exist for getting type of "Params" without any arrays or inilialized_list? template<class Type, class… Params> void InsertInVector(std::vector<Type>& v, const Params&… params) { const auto variadic = {typeid(Params).name()…}; if (typeid(Type).name() != *variadic.begin()) { throw… Read More C++ variadic template: typeid of it, way to optimize

Can't catch exception Firebase Realtime database

I am trying to throw a message when the password is less than 6 characters, but I can’t catch the exception. final email = _email.text; final password = _password.text; try { final userCredential = await FirebaseAuth.instance .createUserWithEmailAndPassword( email: email, password: password ); print(userCredential); } on FirebaseAuthException catch (e) { print(e.runtimeType); print (‘Password should be at… Read More Can't catch exception Firebase Realtime database

Runtime error: reference binding to null pointer of type 'int' (stl_vector.h) c++

I know that this error refers to undefined behavior (I think), but I’ve reread my code 20 times and I don’t see what the UB is!? I’m doing Leetcode 238. Product of Array Except Self and here’s my code (btw I don’t know if this solution is right): class Solution { public: vector<int> productExceptSelf(vector<int>& nums)… Read More Runtime error: reference binding to null pointer of type 'int' (stl_vector.h) c++

Why does a non-constexpr std::integral_constant work as a template argument?

My question is why the following code is valid C++: #include <iostream> #include <tuple> #include <type_traits> std::tuple<const char *, const char *> tuple("Hello", "world"); std::integral_constant<std::size_t, 0> zero; std::integral_constant<std::size_t, 1> one; template<typename T> const char * lookup(T n) { // I would expect to have to write this: // return std::get<decltype(n)::value>(tuple); // But actually this works:… Read More Why does a non-constexpr std::integral_constant work as a template argument?