Boost logo

Boost :

Subject: Re: [boost] [gsoc16] Can I quickly check if the below really is the best approach?
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2016-01-16 06:49:39


On 16 Jan 2016 at 15:06, Shangtong Zhang wrote:

> > // At global scope, allocates no memory whatsoever
> > static const constexpr static_map<int, const char *> 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/



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk