|
| 1 | +#include <seqan3/alphabet/cigar/cigar.hpp> |
| 2 | +#include <seqan3/core/debug_stream.hpp> |
| 3 | + |
| 4 | +int main() |
| 5 | +{ |
| 6 | + std::string cigar_str{"4S134M"}; // input |
| 7 | + |
| 8 | + seqan3::cigar letter1{}; |
| 9 | + seqan3::cigar letter2{}; |
| 10 | + |
| 11 | + // Assign from string |
| 12 | + // convenient but creates an unnecessary string copy "4S" |
| 13 | + letter1.assign_string(cigar_str.substr(0, 2)); |
| 14 | + letter2.assign_string(cigar_str.substr(2, 4)); |
| 15 | + seqan3::debug_stream << letter1 << '\n'; // prints 4S |
| 16 | + seqan3::debug_stream << letter2 << '\n'; // prints 134M |
| 17 | + |
| 18 | + // Assign from std::string_view (No extra string copies) |
| 19 | + // Version 1 |
| 20 | + letter1.assign_string(std::string_view{cigar_str}.substr(0, 2)); |
| 21 | + letter2.assign_string(std::string_view{cigar_str}.substr(2, 4)); |
| 22 | + seqan3::debug_stream << letter1 << '\n'; // prints 4S |
| 23 | + seqan3::debug_stream << letter2 << '\n'; // prints 134M |
| 24 | + // No extra string copiesersion 2 |
| 25 | + letter1.assign_string(/*std::string_view*/ {cigar_str.data(), 2}); |
| 26 | + letter2.assign_string(/*std::string_view*/ {cigar_str.data() + 2, 4}); |
| 27 | + seqan3::debug_stream << letter1 << '\n'; // prints 4S |
| 28 | + seqan3::debug_stream << letter2 << '\n'; // prints 134M |
| 29 | + |
| 30 | + // Assign from char array |
| 31 | + letter2.assign_string("40S"); |
| 32 | + seqan3::debug_stream << letter2 << '\n'; // prints 40S |
| 33 | + |
| 34 | + // Assign from seqan3::small_string |
| 35 | + letter2.assign_string(letter1.to_string()); |
| 36 | + seqan3::debug_stream << letter2 << '\n'; // prints 4S |
| 37 | +} |
0 commit comments