Closed smehringer closed 6 years ago
Currently, it works when you apply the to_char() function first. But I see your point that a direct streaming is helpful.
you can just use the to_char view for strings:
dna4_string foo{"ACGT"_dna4};
std::cout << (foo | view::to_char) << '\n';
edit:
That doesnt work for input, though. I'll have a look if something can be done in the reverse direction with view::char_to<dna4>
. You definetely stream into an std::string and then use view::char_to<dna4>
.
The reason for this is that we (a) recommend people use dna4_vector
and not dna4_string
; and (b) regular vectors are also not streamable. Being streamable is something similar to an implicit conversion which we want to avoid. And e.g. if streaming to a file it would probably make much more sense to not stream the character representation, but the rank representation, maybe even bitcompressed?
Hm, yes streaming to a file would make more sense with the rank representation/bitcompression IF you are a software developer concerned with efficient I/O.. But we do want to attract less advanced users who would be very confused if printing their string outputs numbers or if it doesn't work at all? (Not to support it, only to make them use a vector might not be the proper way :smile: )
In my opinion, using the <<
operator is convenient for scripting or a some quick "manual debugging" and is usually not used in applications anyway. As a developer you want to use some write()
function that features more error handling and could be tagged with the desired output format write(mystring, bitCompressed(), parallelPolicy())
.
Maybe we restrict implicit conversion of strings to streaming to std::cout/cerr
?
Because I really think easy printing of variables is very important for a user friendly interface..
The outcome of a discussion from some time back was the idea of providing a "seqan debug stream" that can be used to print every seqan3 object to the console without enabling an implicit cast to char.
I think alphabet strings like dna4_string should be streamable, since there are several use cases.
Next to the obvious
std::cout << my_dna_string
, I might also want to stream into a dna4_string via anstd::istringstream
. In the case (more unlikely, I know) that a dna4_string is a user defined command line input (maybe "give a promotor sequence"), this is currently not possible because I require option input types to be std::istringstream convertable.@h-2, @joergi-w, @marehr what do you think? (as git blames you as authors of the alphabet module)