Re: [boost] [gsoc16] Can I quickly check if the below really is the best approach?

Hi,
// At global scope, allocates no memory whatsoever static const constexpr static_map
map { { 5, "apple" }, { 8, "pear" }, { 0, "banana" }, ... }; // Works, constexpr "apple" constexpr const char *what_is_5 = map[5]; // Works assert(map[5] && !strcmp(map[5], "apple"); // Works map[5]="orange"; assert(map[5] && !strcmp(map[5], "orange"); // Throws exception as there is no key 6 map[6]; map.at http://map.at/(6);
I have difficulty understanding this, As variable map is const and constexpr, how can map[5]=“orange” work? I don’t know how to implement this, where to store the “orange”. Could anyone help me? Thanks, Shangtong Zhang, Senior Student, School of Computer Science, Fudan University, PRC.

On 16 Jan 2016 at 15:06, Shangtong Zhang wrote:
// At global scope, allocates no memory whatsoever static const constexpr static_map
map { { 5, "apple" }, { 8, "pear" }, { 0, "banana" }, ... }; // Works map[5]="orange"; assert(map[5] && !strcmp(map[5], "orange"); I have difficulty understanding this, As variable map is const and constexpr, how can map[5]=“orange” work? I don’t know how to implement this, where to store the “orange”. Could anyone help me?
Good catch. You are right that if it is const, it cannot be modified without a compiler error. If it is constexpr, it can only be modified in a constexpr evaluation context, and otherwise not. I'll fix the project idea description before I announce the call for GSoC project ideas which will be probably Monday. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
participants (2)
-
Niall Douglas
-
Shangtong Zhang