[gsoc17] Project1: Static map: Can I implement the competency test in g++-7?
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
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
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/
Hi Zheng Luo,
My name is Ruoyun Jing, a third year student from Northwest University in
China, these is the first time i participate in GSoc. For we come from same
country, :) can i have your wechat or QQ to ask you some questions about
GSoC ?:)
Looking forward from you!!
Thanks.
2017-03-04 0:18 GMT+08:00 Vic Luo via Boost
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
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
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/ mailman/listinfo.cgi/boost
--
Northwest University of China
Software Engineering
jingry0321@gmail.com
Hi,
I would like to share my progress on the competency project made
recently. I managed to implement:
constexpr std::pair
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
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
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.
The list should know I've been impressed with what candidate students have sent me to prove their programming competency. It makes me feel old and a little past it.
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.
So the list understands: constexpr mapped_type &at(const key_type &key) const { if(key_not_in_map) throw std::out_of_range(); } This works under constexpr, but annoyingly causes the compiler to generate code which throws std::out_of_range() which is a showstopper. What would be much better: constexpr mapped_type &at(const key_type &key) const { static_assert(!key_not_in_map, "key not in map"); } ... but constexpr functions are not necessarily executed at compile time, so we can't do this. I believe C++ 17's if constexpr() would fix this, but having a C++ 14 solution would be nice. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
participants (3)
-
Niall Douglas
-
Ruoyun Jing
-
Vic Luo