File: small_string.cpp

package info (click to toggle)
seqan3 3.0.2%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,052 kB
  • sloc: cpp: 144,641; makefile: 1,288; ansic: 294; sh: 228; xml: 217; javascript: 50; python: 27; php: 25
file content (18 lines) | stat: -rw-r--r-- 708 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/range/container/small_string.hpp>

int main()
{
    constexpr seqan3::small_string sm{"hello"};     // construct from string literal at compile time!

    static_assert(sm[0] == 'h');                    // This way I can also test it at compile-time

    seqan3::debug_stream << sm.size() << '\n'; // prints 5! (the null character is only stored internally)

    // conversion to a normal string:
    std::string sm_string{sm.str()};
    // access data directly with a pointer to the underlying zero-terminated array:
    char const * sm_cstr{sm.c_str()};

    seqan3::debug_stream << sm << sm_string << sm_cstr << '\n'; // prints "hellohellohello"
}