Tag: constexpr
-
Does a const char* literal string persistently exist as long as the process alive?
12 I have functions like the following: const char* get_message() { return "This is a constant message, will NOT change forever!"; }; const char* get_message2() { return "message2"; }; And I’m planning to use them everywhere my app, even though in different threads. I’m wondering about the life time of these strings, i.e. whether it’s…
-
Is gcc wrong to allow the initialization of a const array member with another array reference?
8 While (re)implementing a simple constexpr map, I wrote this (godbolt): template <class key_type, class value_type, int N> class flat_map { private: struct pair { key_type key; value_type value; }; const pair elements[N]; public: consteval flat_map(const pair (&arr)[N]) noexcept : elements(arr) // works on gcc?! {} [[nodiscard]] consteval value_type operator[](const key_type key) const { for…