I wrote this answer.
When the string value_type is char , the number of elements needed in the lookup table is 256. For a double-byte encoding, 65536. For a four-byte encoding, the lookup table will have a little over 4 billion entries, with a probable size of 16 GB! And most of them will not be used.
So, the first thing to recognize, even if we restrict the types char and wchar_t , it can still be untenable. Similarly, if we want to do is_permutation for sequences of type int .
We could have a specialization of std::is_permutation<> for integral types of 1 or 2 bytes in size. But this is somewhat reminiscent of std::vector<bool> , which not everyone considers a good idea in retrospect.
We could also use a lookup table based on std::map<T, size_t> , but it will probably be heavy, so it may not be a win in performance (or at least not always). It might be worth doing one for a detailed comparison.
In general, I am not mistaken in the C ++ standard, not including the high-performance version of is_permutation for char . Firstly, because in the real world Iβm not sure that this is the most common use of the template, and secondly, because STL is not all and all algorithms, especially where domain knowledge can be used to speed up calculations for special cases .
If it turns out that is_permutation for char quite common in the wild, C ++ library developers will, within their rights, provide specialization for it.
John zwinck
source share