Boost logo

Boost :

Subject: Re: [boost] [gsoc17] Project1: Static map: Can I implement the competency test in g++-7?
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2017-03-04 08:26:51


> And my question is, am I allowed to implement the competency test of
> static_map in g++-7? I have just implemented my own version of
> static_map which supports the following operations:
>
> constexpr StaticMap<int, const char *, 3> m(make_pair(2, "abc"),
> make_pair(4, "def"), make_pair(6, "ghi"));
>
> if (!m[4])
> abort();
> const char *foo = m[2];
> return 0;

Note the compiler will elide m[2] in any case because you do nothing
with its result. Therefore the compiler can assume the call does nothing
and remove it.

> So I was wondering did I pass the test?

Maybe. You should be aware that other students have submitted some
really good implementations already, ones which work perfectly on both
GCC and clang and have a STL idiomatic API and have O(1) compile time
complexity and O(N) storage overheads. I have yet to see a student
submit a working implementation for Visual Studio however (VS2017
finally has full constexpr, it should be doable).

Also remember that the mapped values by static_map are *mutable* even
though the map itself is all compile-time. And the mutability should be
compiled into minimum assembler e.g.:

m[2] = 5;

turns into:

lea addr_of_map, %eax;
movl #5, [%eax, #someoffset];

... or something similarly minimum.

Feel free to email me privately with a link to your implementation for a
quick review.

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