October 24, 2024
Chicago 12, Melborne City, USA
templates

Creating constexpr map filled by calls to a constexpr function in C++ 17


I have a constexpr function that calculates CRC at compile time. I need to create a map between CRCs that are generated by this function and string inputs and use them in runtime (Even better if it is also possible to use it in compile time too).

I’m using C++ 17 by the way.

This is my function signature:

        template <size_t length>
        static constexpr unsigned int getCrc32(const char (&str)[length])
        {
              //calculate compile time crc
        }

I tried different ways with templates and other things but I either end up with compiling code with undefined behavior or unmodifiable contexpr wall.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video