Changes between Version 4 and Version 5 of SoC2016
- Timestamp:
- Jan 11, 2016, 9:44:28 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SoC2016
v4 v5 138 138 ==== Programming competency test ==== 139 139 Write a function which uses one of the compile time string hashing techniques at https://stackoverflow.com/questions/2111667/compile-time-string-hashing 140 to generate a constexpr `std::array<unsigned>` of its input strings. The function ought to have the following140 (or a constexpr hash function of your preference) to generate a constexpr `std::array<unsigned>` of its input strings. The function ought to have the following 141 141 prototype: 142 142 … … 145 145 template<class... Strings> constexpr std::array<unsigned, sizeof...(Strings)> hash_strings(Strings&&... strings); 146 146 147 // Example of usage 148 constexpr std::array<unsigned, 4> string_hashes = hash_strings("google", "summer", "of", "code"); 147 // Examples of usage 148 constexpr std::array<unsigned, 0> string_hashes0 = hash_strings(); 149 constexpr std::array<unsigned, 2> string_hashes2 = hash_strings("niall", "douglas"); 150 constexpr std::array<unsigned, 4> string_hashes4 = hash_strings("google", "summer", "of", "code"); 151 // This should fail elegantly and usefully ... 152 //constexpr std::array<unsigned, 0> string_hashes_fail = hash_strings(5); 149 153 }}} 154 155 In your submission you should: 156 157 1. Explain why you chose the constexpr string hash function you did and the strengths of your choice over other choices. 158 2. Test that the output is identical whether executed by the compiler at compile time, or at runtime. 159 3. '''Prove''' that the compile time constexpr implementation generates no runtime code whatsoever. 150 160 151 161 Submission of the programming test should be via copying and pasting the code you wrote into the end of the proposal you submit to Google Melange.