Re:Fix Boyer-Moore searcher with the Rytter correction
by karma_fountain on Friday April 17, 2020 @03:08AM
(#22896882)
Nice fix! It's been a while since I've done c++ so does the following code
actually use a units quantifier on the 10, i.e. does 10s mean 10 seconds? Is that a library thing? Cool if so.
[ Parent
| on HN ]
Re:Fix Boyer-Moore searcher with the Rytter correction
by sgn on Friday April 17, 2020 @03:38AM
(#22897005)
It’s called user-defined literal suffix in C++11.
https://en.cppreference.com/w/cpp/language/user_literal The “s” suffix come with C++14 https://en.cppreference.com/w/cpp/chrono/operator%22%22s
Re:Fix Boyer-Moore searcher with the Rytter correction
by andijcr on Friday April 17, 2020 @03:58AM
(#22897089)
that's a user defined literal, a language feature: https://en.cppreference.com/w/cpp/language/user_literal
the std::chrono library reserved some suffixes (under std::literals::chrono_literals) for time units https://en.cppreference.com/w/cpp/symbol_index/chrono_litera...
Re:Fix Boyer-Moore searcher with the Rytter correction
by StephanTLavavej on Friday April 17, 2020 @08:56AM
(#22898549)
And this works because I have `using namespace std;` in the test, which makes all of the Standard Library's "user"-defined literals available. So does `using namespace std::literals;` (without dragging in other names). There's also the extremely fine-grained `using namespace std::chrono_literals;` (no need to type `using namespace std::literals::chrono_literals;` due to how inline namespaces work) which drags in just the chrono duration literals. Finally, `using namespace std::chrono;` drags in all of the chrono names and the chrono literals.
The reason that a using-directive of some kind is necessary is that UDLs are provided by operators, and directly spelling out the operator in order to namespace-qualify it would be self-defeating. (Many people dislike `using namespace std;` and I understand their point, but when one works on the STL all day every day, this using-directive is sure nice for test code.)
My exhaustive test case for this is (demonstrating all the different ways that chrono literals can be accessed): https://github.com/microsoft/STL/blob/31419650d472932dd24b9c...