Это чрезвычайно быстро, так что Вы были бы поражены. Внутренне это, вероятно, использует некоторую сумасшедшую структуру типа B-дерева для расположения соответствий их общими префиксами. Я использую его с более чем 200, находят и заменяют строки, и это все еще проходит 1 МБ меньше чем в 100 мс. Для всех кроме тривиально маленьких строк strtr () даже значительно быстрее, чем strtolower () при выполнении той же самой вещи, даже принимая набор символов во внимание. Вы могли, вероятно, записать весь синтаксический анализатор с помощью последовательных вызовов strtr, и это будет быстрее, чем обычное соответствие регулярного выражения, выяснит тип маркера, произведет это или что, следующий вид регулярного выражения вещи.
я писал текстовый нормализатор для разделения текста в слова, печатание строчными литерами, удаляя пунктуацию и т.д. и strtr было моим швейцарским ножом, это разбило штаны от регулярных выражений или даже str_replace ().
I would say that the second usage is rather uncommon, at least in the code that I've seen so far (and I've seen quite a lot C++ of code). Could you explain what the reasoning behind the second technique is?
You will normally use an anonymous namespace in a C++ implementation file to achieve the same thing that 'static' would do in C (or C++, but we'll gloss over that), namely restricting the visibility of the symbols to the current translation unit. The typedef doesn't actually produce symbols that are exported for the linker to see as they don't create anything 'concrete' in the sense of anything concrete that you could link against.
My recommendation? I'd go with the first notation. The second one adds an unnecessary complication and in my opinion, doesn't buy you anything.
There is not much point in placing typedefs in anonymous namespaces. The main use for anonymous namespaces is to avoid symbol collision between translation units by placing definitions with external linkage in them.