|
Boost : |
Subject: Re: [boost] [gsoc17] Project1: Static map: Can I implement the competency test in g++-7?
From: Vic Luo (vicluo96_at_[hidden])
Date: 2017-03-07 11:56:36
Hi,
I would like to share my progress on the competency project made
recently. I managed to implement:
constexpr std::pair<const int, const char *> map_data[] = {
{ 5, "apple" },
{ 8, "pear" },
{ 0, "banana" }
};
constexpr auto cmap = make_static_map(map_data);
if (!has_str(cmap, "apple")) abort();
if (!has_str(cmap, "pear")) abort();
if(!cmap[8]) abort();
const char *foo=cmap[5];
const char *bar = std::get<2>(cmap);
if (strcmp(bar, "banana")) abort();
// system(cmap[8]);
auto m = make_static_map(map_data);
m[0] = "strawberry";
system(m[0]);
with zero runtime overhead and O(1) compile-time complexity(measured by
template instantiation) on g++-6+ and clang-3.6+ with flag -std=c++14
and -O3. It is also experimented that zero runtime and O(1) compile-time
complexity could be achieved on constant path of g++-5. In the next few
days, I'm going to focus on MSVC2017 efficient implementation.
Regarding the design of static_map's interface, I doubt that is it
possible or worthwhile to implement a subscript-like operator/function
that checks boundary at compile time(given that key is a constant
expression)? Compilation errors tend to be more likely to be discovered
than runtime exception.
Thanks,
On 03/04/2017 12:18 AM, Vic Luo wrote:
> Hi,
>
> I'm Zheng Luo, a third-year undergraduate from Shanghai Jiaotong
> University who have special interest in C++ programming(especially for
> templates). This is my second year of applying Google Summer of Code and
> I'm willing to contribute to Static Map project mentioned on SoC2017
> page. Previously I worked for a company as a C++ intern for months on
> Chromium-related projects where I gained some experience about C++ in
> industry.
>
> 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;
>
>
> which is compiled into assembly as:
>
> main:
> xorl %eax, %eax
> ret
>
> under g++-7 with -std=c++1z -O3
>
> So I was wondering did I pass the test?
>
> Thanks,
>
-- --------------------------------- Vic Luo Shanghai Jiaotong University Key fingerprint 0x98809ca08bf5662a
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk