On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote:
I'm making anagrams. According to the nextPermutation() docs, I
need to 'sort by less' to get all permutations. ... Except the
doc page doesn't mention how to do that, nor does
std.algorithm.sort show how to sort a string. ... and the
google results on the dlang forums from 2017 don't work.
I've tried .byCodeUnit. , .representation. I've tried sorting
on the dchar. I've tried sorting the on string.
The closest I've gotten:
string word = "bar";
string line2 = toLower!(string)(word);
dchar[] line3 = sort(line2.to!(dchar[]));
"Error: cannot implicitly convert expression sort(to(line2)) of
type SortedRange!(dchar[], "a < b") to dchar[]"
You need to convert the sort output to dchar[], e.g.
---
dchar[] line3 = sort(line2.to!(dchar[])).to!(dchar[]);
---
Cheers,
Norm