Skip to content

Bug: example of concatenation by expression templates not working #301

@orefkov

Description

@orefkov

Describe the bug

I tried to reproduce that example from the documentation, but it didn't compile.

auto email = sz::concatenate(name, "@", domain, ".", tld);   // 0 allocations
auto email = name | "@" | domain | "." | tld;                // 0 allocations
sz::string email = name | "@" | domain | "." | tld;          // 1 allocations

Steps to reproduce

That source not compiled.

#include <stringzilla/stringzilla.hpp>
namespace sz = ashvardanian::stringzilla;
void stringzilla_concat(sz::string_view name, sz::string_view domain, sz::string_view tld) {
    auto email = sz::concatenate(name, "@", domain, ".", tld);
    sz::string result = email;
}

Error:

error: type 'ashvardanian::stringzilla::basic_string_slice<const char> &' cannot be used prior to '::' because it has no members
|     using value_type = typename first_type_::value_type;

Need std::remove_cvref_t<first_type_>::value_type;.

That sources not comiled too

void stringzilla_concat(sz::string_view name, sz::string_view domain, sz::string_view tld) {
    auto email = name | "@" | domain | "." | tld;
    sz::string result = email;
}

Error:

error: invalid operands to binary expression ('sz::string_view' (aka 'basic_string_slice<const char>') and 'const char[2]')
|     auto email = name | "@" | domain | "." | tld;

And that

void stringzilla_concat(sz::string name, sz::string_view domain, sz::string_view tld) {
    auto email = name | "@" | domain | "." | tld;
    sz::string result = email;
}

Error:

error: no viable conversion from 'concatenation<concatenation<concatenation<concatenation<basic_string_slice<const char>, 
basic_string_slice<const char>>, basic_string_slice<const char> &>, const char (&)[2]>, basic_string_slice<const char> &>'
to 'sz::string' (aka 'basic_string<char, std::allocator<char>>')

And that

void stringzilla_concat(sz::string name, sz::string_view domain, sz::string_view tld) {
    auto email = name | "@" | domain | "." | tld;
    sz::string result{email};
}

Error

error: member reference base type 'const char[2]' is not a structure or union
|     std::size_t size() const noexcept { return first.size() + second.size(); }

Expected behavior

Can compiled only that:

void stringzilla_concat(sz::string name, sz::string_view domain, sz::string_view tld) {
    auto email = name | sz::string_view{"@"} | domain | sz::string_view{"."} | tld;
    sz::string result{email};
}

or

void stringzilla_concat(sz::string_view name, sz::string_view domain, sz::string_view tld) {
    auto email = sz::concatenate(sz::string_view{name}, sz::string_view{"@"}, sz::string_view{domain}, sz::string_view{"."}, sz::string_view{tld});
    sz::string result{email};
}

StringZilla version

v4.6

Operating System

Windows 10, Clang19, C++20. Ubuntu 22.4, GCC-13

Hardware architecture

x86

Which interface are you using?

C++ bindings

Contact Details

orefkov@gmail.com

Are you open to being tagged as a contributor?

  • I am open to being mentioned in the project .git history as a contributor

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions