hffix icon indicating copy to clipboard operation
hffix copied to clipboard

some errors

Open jackeykong opened this issue 3 years ago • 11 comments

  1. On Windows, there is no 'ssize_t' type.
  2. the 'std::string_view' has no begin and end members. void push_back_string(int tag, std::string_view s) { push_back_string(tag, s.begin(), s.end()); }

jackeykong avatar Oct 09 '21 15:10 jackeykong

Hi, thanks for opening this issue.

  1. On Windows, there is no 'ssize_t' type.

You're right, ssize_t is not standard and we shouldn't use it. I'll fix that.

  1. the 'std::string_view' has no begin and end members. void push_back_string(int tag, std::string_view s) { push_back_string(tag, s.begin(), s.end()); }

std::string_view begin and end are standard, starting in C++17. https://en.cppreference.com/w/cpp/string/basic_string_view Do you have a suggestion for what to do about that?

jamesdbrock avatar Oct 10 '21 23:10 jamesdbrock

I tagged v1.1.1 for the ssize_t bugfix. https://github.com/jamesdbrock/hffix/releases/tag/v1.1.1

jamesdbrock avatar Oct 11 '21 00:10 jamesdbrock

I also found a small error in the Multi-threaded Sending section of the readme.md file. hffix::message_reader::const_iterator i = std::find(r.begin(), r.end(), hffix::tag_equal(hffix::tag::MsgSeqNum)); if (i != r.end()) { std::snprintf(const_cast<char*>(i->begin()), i->size(), "%.8i", next_sequence_number++); }

  1. should be use std::find_if to find out iterator i
  2. iterator i has no begin and size members

jackeykong avatar Oct 11 '21 01:10 jackeykong

Hi, thanks for opening this issue.

  1. On Windows, there is no 'ssize_t' type.

You're right, ssize_t is not standard and we shouldn't use it. I'll fix that.

  1. the 'std::string_view' has no begin and end members. void push_back_string(int tag, std::string_view s) { push_back_string(tag, s.begin(), s.end()); }

std::string_view begin and end are standard, starting in C++17. https://en.cppreference.com/w/cpp/string/basic_string_view Do you have a suggestion for what to do about that?

But, std::string_view::begin and std::string_view::end return std::basic_string_view<CharT,Traits> instead of const char*

jackeykong avatar Oct 11 '21 01:10 jackeykong

I also found a small error in the Multi-threaded Sending section of the readme.md file.

Thanks!

jamesdbrock avatar Oct 11 '21 03:10 jamesdbrock

But, std::string_view::begin and std::string_view::end return std::basic_string_view<CharT,Traits> instead of const char*

They return a std::basic_string_view<char>::const_iterator which will be type const char *. Or is it not type const char * in your Windows environment? I guess if it's not const char * then push_back_string(int tag, std::string_view s) will fail to typecheck, is that what's happening for you?

https://en.cppreference.com/w/cpp/string/basic_string_view

https://docs.microsoft.com/en-us/cpp/standard-library/string-view-typedefs?view=msvc-160#string_view

jamesdbrock avatar Oct 11 '21 03:10 jamesdbrock

But, std::string_view::begin and std::string_view::end return std::basic_string_view<CharT,Traits> instead of const char*

They return a std::basic_string_view<char>::const_iterator which will be type const char *. Or is it not type const char * in your Windows environment? I guess if it's not const char * then push_back_string(int tag, std::string_view s) will fail to typecheck, is that what's happening for you?

https://en.cppreference.com/w/cpp/string/basic_string_view

https://docs.microsoft.com/en-us/cpp/standard-library/string-view-typedefs?view=msvc-160#string_view

Yes, i use visual studio 2017 on windows, the error message is error C2664: 'void hffix::message_writer::push_back_string(int,std::string_view)': cannot convert argument 2 from 'std::_String_view_iterator<_Traits>' to 'const char *'

jackeykong avatar Oct 11 '21 03:10 jackeykong

I don't have easy access to a Windows machine so it's inconvenient for me to write a fix for this because I can't test it on Windows. Would you like to make a PR to fix this problem?

jamesdbrock avatar Oct 19 '21 00:10 jamesdbrock

Yes, I will be happy to do PR. just modify as follows : void push_back_string(int tag, std::string_view s) { push_back_string(tag, s.data(), s.data() + s.length()); }

jackeykong avatar Oct 25 '21 02:10 jackeykong

Yes, I will be happy to do PR.

Yes please, that looks good. https://en.cppreference.com/w/cpp/string/basic_string_view/data

Do you know how to open a Pull Request? https://github.com/jamesdbrock/hffix/pulls

jamesdbrock avatar Oct 26 '21 04:10 jamesdbrock

I created pull request #56 after encountering the same problem with MSVC

enricodetoma avatar Apr 17 '24 16:04 enricodetoma