Skip to content

Example fails to compile (gcc 12.2.1) #4

@SnapperTT

Description

@SnapperTT

Nice library. Here are the issues:

  1. example.cpp needs a #include <cstdint> for std::uint32_t support

  2. Here is the other compile errors:

[ 25%] Building CXX object example/CMakeFiles/examples.dir/main.cpp.o
cd /home/twigger/faststring/FastString/example && /usr/bin/c++  -I/home/twigger/faststring/FastString/include -O3 -O3 -DNDEBUG -std=c++20 -Wall -Wextra -pedantic -Werror -MD -MT example/CMakeFiles/examples.dir/main.cpp.o -MF CMakeFiles/examples.dir/main.cpp.o.d -o CMakeFiles/examples.dir/main.cpp.o -c /home/twigger/faststring/FastString/example/main.cpp
/home/twigger/faststring/FastString/example/main.cpp: In function ‘int main()’:
/home/twigger/faststring/FastString/example/main.cpp:39:51: error: ‘std::basic_string_view<char>{2, ((const char*)(& e.fss::basic_str<char, 7, std::char_traits<char> >::buffer_))}’ is not a constant expression
   39 |     constexpr auto e_sub_str = e.str().substr(0, 2);    // e_sub_str is "ab"
      |                                                   ^
/home/twigger/faststring/FastString/example/main.cpp:96:40: error: ‘std::basic_string_view<char>{4, ((const char*)(& t.main()::test_struct::c_.fss::basic_str<char, 7, std::char_traits<char> >::buffer_))}’ is not a constant expression
   96 |     constexpr const auto t_a = t.get_c();
      |                                        ^
make[2]: *** [example/CMakeFiles/examples.dir/build.make:79: example/CMakeFiles/examples.dir/main.cpp.o] Error 1
  1. Finally you use std::size_t for your size type. This needlessly makes, eg, string64 take up 8 more bytes than necessary. Why not use something like uint8_t and have a static_assert that the size is suitable for the capacity. Or even better, have a template argument for the size type, eg using string64 = fss::fixed_size_str<62, std::uint8_t>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions